题目链接:http://poj.org/problem?id=1961
#include <stdio.h>
#include <string.h>
char S[1000010];
int next[1000010];
int main()
{
int n,time = 1;
int i,j,length;
while(scanf("%d",&n) && n)
{
i = 0;
j = -1;
next[0] = -1;
scanf("%s",S);
while(i < n)
{
if(j == -1 || S[i] == S[j])
{
++i;
++j;
next[i] = j;
}
else
j = next[j];
}
printf("Test case #%d\n",time);
for(i = 1; i <= n; ++i)
{
length = i - next[i];//循环节长度
if(i != length && i % length == 0)
printf("%d %d\n", i, i/length);
}
time++;
printf("\n");
}
return 0;
}