# POJ 2406 - Power String

Description

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


#include <cstdio>
#include <cstring>

char str[1000005];
int tar[1000005];

int main()
{
while (scanf("%s", str) != EOF)
{
if (strcmp(str, ".") == 0)
break;
int len = strlen(str);
tar[0] = 0;

int cur = -1;
for (int i = 1; i < len; ++i)
{
while (cur > 0 && str[cur+1] != str[i])
cur = -1;
if (str[cur+1] == str[i])
cur++;
tar[i] = cur;
}
if (len % (len - tar[len - 1] -1) == 0)
printf("%d\n", len / (len - tar[len - 1] - 1));
else
printf("1\n");
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：POJ 2406 - Power String 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)