Description
Given two strings A and B we define a * B to be their concatenation. for example, if a = "ABC" and B = "def" Then a * B = "abcdef ". if we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a ^ 0 = "" (the empty string) and a ^ (n + 1) = A * (a ^ N ).
Input
Each test case is a line of input representing S, a string of printable characters. the length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you shoshould print the largest N such that S = a ^ N for some string.
Sample Input
abcdaaaaababab.
Sample output
143 code:# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; char s [1000005]; // a runtime error occurs if the result is not specified .. Int next [1000005]; int S1, SS; void getnext (char * s) {int I = 0; Int J =-1; next [0] =-1; while (I <S1) {If (j =-1 | s [I] = s [J]) {++ I; ++ J; next [I] = J;} elsej = next [J];} I = s1-j; If (S1% I = 0) Ss = S1/I; else Ss = 1; return;} int main () {While (scanf ("% s", S) {If (s [0] = '. ') break; S1 = strlen (s); getnext (s); cout <SS <Endl;} return 0 ;}
Poj 2406 power strings KMP