- #include<stdio.h>
- #define M 1000010
- int i,n,next[M];
- char s[M];
- void getNext()
- {
- int j=-1;
- next[0]=-1;
- for(i=1;s[i];i++){
- while(j!=-1&&s[j+1]!=s[i])j=next[j];
- if(s[j+1]==s[i])j++;
- next[i]=j;
- }
- }
- int main()
- {
- int k=0;
- while(scanf("%d",&n),n){
- scanf("%s",s);
- printf("Test case #%d\n",++k);
- getNext();
- for(i=1;i<=n;i++)
- if(i%(i-next[i-1]-1)==0&&next[i-1]>-1)
- printf("%d %d\n",i,i/(i-next[i-1]-1));
- puts("");
- }
- return 0;
- }
时间: 2024-12-18 22:11:38