Period
Time limit1sMemory limit128 MB
For every prefix of a string, find the largest exponent K such that the prefix equals some string A repeated K times, using KMP failure function.
- Level
Medium4 of 10
- Topics
- String matching, String, Implementation
- Solved
- No attempts yet
Problem
You are given a string made of characters whose ASCII codes are between and inclusive. For every prefix of , you want to decide whether that prefix is a periodic string.
More precisely, for each with , consider the prefix of of length . You want the largest such that this prefix can be written as for some string .
Here denotes the string formed by concatenating exactly times. For example, if is abad and , then is abadabadabad.
Input
The input consists of several test cases. Each test case is given on two lines. The first line contains an integer , the length of the string (). The second line contains the string . The end of the input is indicated by a line containing a single .
Output
For each test case, print Test case # followed by the test case number on one line. Then, for every length whose prefix can be written as with a largest exponent , print the length and that value on one line, separated by a space. Print these lines in increasing order of the prefix length . After the answer for each test case, print one blank line.