2 solutions
-
3
#include<bits/stdc++.h> using namespace std; const int N=1e6+10; int ne[N]; char s[N]; int main() { while(cin>>s+1) { if(s[1]=='.') { break; } memset(ne,0,sizeof(ne)); int n=strlen(s+1); for(int i=2,j=0;i<=n;i++) { while(j&&s[i]!=s[j+1]) { j=ne[j]; } if(s[i]==s[j+1]) { j++; } ne[i]=j; } int t=n-ne[n]; if(n%t==0) { cout<<n/t<<"\n"; } else { cout<<"1\n"; } } return 0; } -
2
#include<bits/stdc++.h> using namespace std; string s,s1,s2; int n,x; vector<int>v; bool f; void ys(int n) { v.clear(); for(int i=1;i<=sqrt(n);i++) { if(n%i==0) { if(i!=n/i) { v.push_back(i); v.push_back(n/i); } else { v.push_back(i); } } } } int main() { while(cin>>s,s!=".") { n=s.size(); ys(n); s=" "+s; sort(v.begin(),v.end()); for(int j=0;j<v.size();j++) { f=true; x=v[j]; s1=s.substr(1,x); for(int i=x+1;i<=n;i+=x) { s2=s.substr(i,x); if(s1!=s2) { f=false; break; } } if(f) { cout<<n/x<<"\n"; break; } } } return 0; }
- 1
Information
- ID
- 314
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 4
- Accepted
- 3
- Uploaded By