Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
最长公共前后缀
//Full of love and hope for life
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
using namespace std;
char n[1000010];
int nex[1000010];
void getnext(char a[],int x){
int j=-1;
nex[0]=-1;
int i=0;
while(i<x){
if(j==-1||a[i]==a[j]){
i++;
j++;
nex[i]=j;
}
else{
j=nex[j];
}
}
}
/*
int kmp(char a[],char b[],int x,int y){
getnext(b,y);
int j=-1;
for(int i=0;i<x;i++){
while(j!=-1&&a[i]!=b[j+1]){
j=nex[j];
}
if(a[i]==b[j+1]){
j++;
}
if(j==y-1){
ans++;
}
}
return ans;
}
*/
int main(){
while(scanf("%s",n)){
if(n[0]=='.'){
break;
}
int len=strlen(n);
getnext(n,len);
int t=len-nex[len];
if(len%t==0){
cout << len/t << endl;
}
else{
cout << 1 << endl;
}
}
return 0;
}