The main idea: the same problem with poj2406 see http://www.cnblogs.com/zhanzhao/p/4761477.html
Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN =1000005;7 8 intNEXT[MAXN];9 Ten void Get(Char*s) { One intL =strlen (s); A intj =0, k =-1; -next[0] = -1; - while(J <l) { the if(k = =-1|| S[J] = =S[k]) { - - - + //if (s[++j] = = S[++k]) { - //Next[j] = next[k]; + //} else { A //next[j] = k; at // } -NEXT[++J] = + +K; -}Else { -K =Next[k]; - } - } in } - CharS[MAXN]; to + intMain () { - intN; the intKase =1; * while(SCANF ("%d", &n) &&N) { $scanf"%s", s);Panax Notoginsengprintf"Test Case #%d\n", kase++); - Get(s); the intL =strlen (s); + //for (int i = 0; I <= l; i++) { A //printf ("%d", Next[i]); the //}puts (""); + for(inti =2; I <= l; i++) { - intAns =1; $ if(i% (i-next[i]) = =0) { $Ans = I/(i-next[i]); - } - if(Ans >1) { theprintf"%d%d\n", I, ans); - }Wuyi } thePuts""); - } Wu}View Code
Poj1961period "KMP Next Array"