对next数组还是理解的不够透彻,要死要死要死
#include<iostream>
#define maxn 1001000
using namespace std;
string str;
int nextt[maxn];
void kmp()
{
int l=0,k=-1;
nextt[0]=-1;
while(l<str.size())
{
if(k==-1||str[l]==str[k]) nextt[++l]=++k;
else k=nextt[k];
}
}
int main()
{
int n;
int casee=1;
cin.sync_with_stdio(false);
while(cin>>n&&n)
{
cin>>str;
kmp();
int ans=0;
cout<<"Test case #"<<casee++<<endl;
for(int i=2;i<=n;i++)
{
int temp=i-nextt[i];
if(i%temp==0&&i!=temp)
{
ans=i/temp;
cout<<i<<" "<<ans<<endl;
}
}
cout<<endl;
}
return 0;
}