KMP水题。。找前缀最小循环节个数。。。直接看 第 i 是否是 i - nex[i] 倍数就好了。。。
太菜了。。。kmp 还得抄板子。。。。。别忘了最后还得再加个换行。。。不然会pe
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1e6+5;
int n; char s[maxn];
int nex[maxn];
inline void getFail(char *p, int *f)
{
int len=strlen(p);
f[0] = f[1] = 0;
for(register int i=1;i<len;i++)
{
int j = f[i];
while(j && p[i]!=p[j])j=f[j];
f[i+1] = p[i]==p[j] ? j+1:0;
}
}
int main()
{
int cas=1;
while(~scanf("%d",&n) && n)
{
printf("Test case #%d\n",cas++);
cin>>s; memset(nex, 0, sizeof nex);
getFail(s, nex);
for(int i=2;i<=n;i++)
{
if(nex[i]!=0 && i%(i-nex[i])==0)
cout<<i<<' '<<i/(i-nex[i])<<endl;
}
cout<<endl;
}
return 0;
}