#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define maxn 1100000
int next[maxn],n;
char st[maxn];
void getnext(int len)
{
next[0]=next[1]=0;
for(int i=1;i<n;i++)
{
int j=next[i];
while(j&&st[i]!=st[j])
{
j=next[j];
}
if(st[i]==st[j])
{
next[i+1]=j+1;
}
else
{
next[i+1]=0;
}
}
}
int main()
{
int cas=0;
while(scanf("%d",&n)&&n)
{
scanf("%s",st);
getnext(n);
cas++;
printf("Test case #%d\n",cas);
for(int i=2;i<=n;i++)
{
if(next[i]&&i%(i-next[i])==0)
printf("%d %d\n",i,i/(i-next[i]));
}
printf("\n");
}
return 0;
}
hdu1358 Period kmp+模拟
最新推荐文章于 2022-02-17 00:10:51 发布