同poj 1961
#include <stdio.h>
char s[1000010];
int next[1000010];
int len;
void getNext()
{
int i,j;
next[0] = -1;
i = 0;
j = -1;
while(i < len)
{
if(j == -1 || s[i] == s[j])
{
++i;
++j;
next[i] = j;
}
else
j = next[j];
}
}
int main()
{
int time = 0;
int i,length;
while(scanf("%d",&len) && len != 0)
{
++time;
scanf("%s",s);
printf("Test case #%d\n",time);
getNext();
for(i = 1; i <= len; ++i)
{
length = i-next[i];
if(i != length && i%length == 0)
printf("%d %d\n",i,i/length);
}
printf("\n");
}
return 0;
}