2 solutions

  • 3
    @ 2025-11-29 19:33:28
    #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;
    }
    
    
    

    Information

    ID
    314
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    5
    Accepted
    4
    Uploaded By