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