Logo
(追記) (追記ここまで)

16651번 - Distinct Substrings 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB103312432.877%

문제

Diana bought a Long Random String Generator on some weird website. She planned to generate a long string s of length n and then use its contiguous substrings as passwords for other weird websites.

Soon she discovered that the generated string s of length n was not random at all, but rather a string p of length k repeated many times and then cut to length n. Thus, s[i] = p[i mod k] for all i from 0 to n − 1.

Diana wonders how many different passwords she can get from the generated string. Help her find the number of distinct non-empty substrings in string s.

입력

The first line of the input contains a string p consisting of k lowercase English letters (1 ≤ k ≤ 1000).

The second line contains an integer n (k ≤ n ≤ 109).

출력

Output the number of distinct non-empty substrings in s.

제한

예제 입력 1

abba
7

예제 출력 1

20

예제 입력 2

a
42

예제 출력 2

42

노트

In the first example, the generated string is abbaabb. It contains 20 distinct non-empty substrings: a, b, aa, ab, ba, bb, aab, abb, baa, bba, aabb, abba, baab, bbaa, abbaa, baabb, bbaab, abbaab, bbaabb, abbaabb.

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > NEERC Northern Subregional 2018 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /