KMP........ but for the easy data, you can AC it in any way,(my code is not KMP)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[10001];
char b[5001],c[5001];
int main()
{
int i,m,j,k;
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%s",a);
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
int len=strlen(a);
int flag;
for(k=1;k<=len/2;k++)
{
flag=1;
if(len%k!=0) continue;
for(j=0;j<k;j++)
{
b[j]=a[j];
}
for(int l=1;l<len/k;l++)
{
for(int w=0;w<k;w++)
{
c[w]=a[l*k+w];
}
if(strcmp(b,c)!=0)
{
flag=0;
break;
}
}
if(flag==1) break;
}
if(flag==1) printf("%d\n",len/k);
else printf("1\n");
}
return 0;
}