分析:
KMP变形,找到最短的匹配子串。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char B[1000005];
int nxt[1000005];
int m,cas;
void makenext()
{
int l,r;
l=-1;r=0;nxt[0]=-1;
while(r<=m){
if(l==-1||B[l]==B[r]){
nxt[++r]=++l;
}else{
l=nxt[l];
}
}
}
int main()
{
// freopen("in.txt","r",stdin);
cas=1;
while(~scanf("%d",&m)&&m){
scanf("%s",B);
makenext();
printf("Test case #%d\n",cas++);
for(int i=2;i<=m;++i){
if(nxt[i]&&i%(i-nxt[i])==0){
printf("%d %d\n",i,i/(i-nxt[i]));
}
}
printf("\n");
}
return 0;
}