提交时间:2022-04-15 13:41:51

运行 ID: 48711

#include <bits/stdc++.h> using namespace std; char t[1000005]; int n[1000005],x; void Init(){ for(int i=2,j=0;i<=x;i++){ while(j&&t[j+1]!=t[i]) j=n[j]; j+=(t[j+1]==t[i]); n[i]=j; } } int main(){ while(cin>>(t+1)){ if(t[1]=='.') break; x=strlen(t+1); Init(); printf("%d\n",x%(x-n[x])?1:x/(x-n[x])); } return 0; }