重新理解了一下next数组是失配的之后前一个在哪
然后又理解了一下改进算法
然后记住一个结论吧,就是循环节=i-next[i]&&next[i]!=0 (i%(i-next[i])==0)
i是当前字符减一的长度
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;
char s[1000005];
int next[1000005];
int main()
{
int n;
for (int ci=1;scanf("%d",&n)&&n!=0;ci++)
{
scanf("%s",&s);
next[0]=-1;
for (int i=0,j=-1;i<n;)
{
if (j==-1||s[i]==s[j]) next[++i]=++j;
else j=next[j];
}
printf("Test case #%d\n",ci);
for (int i=1;i<=n;i++)
if (i%(i-next[i])==0&&next[i]!=0)
printf("%d %d\n",i,i/(i-next[i]));
printf("\n");
}
return 0;
}