标签:
#include <iostream> #include <cstring> #include <cstdio> using namespace std; int next1[1000010]; int m; char b[1000010]; void build_next() { int i=0; int j=-1; next1[0]=-1; while(i<m) { while(j!=-1&&b[i]!=b[j]) { j=next1[j]; } next1[++i]=++j; } } int main() { int num=1; while(scanf("%d",&m)!=EOF) { if(m==0) break; scanf("%s",&b); cout<<"Test case #"<<num<<endl; num++; build_next(); for(int i=2;i<=m;i++) { if(next1[i]==0) continue; int jie=i-next1[i]; if(i%jie==0) { cout<<i<<" "<<(i/jie)<<endl; } } cout<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/wsruning/p/5525783.html