6777: 「一本通 2.1 练习 1」Power Strings
[Creator : ]
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)$.
假设 $s$ 可以由 $t$ 重复 $k$ 次拼成,即 s=tttt……tt,我们称为 $s=t^k$。先给定一个字符串 $s$,求最大的 $n$ 使得存在 $t$ 满足 $s=t^n$。
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)$.
假设 $s$ 可以由 $t$ 重复 $k$ 次拼成,即 s=tttt……tt,我们称为 $s=t^k$。先给定一个字符串 $s$,求最大的 $n$ 使得存在 $t$ 满足 $s=t^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 $10^6$ 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 1 Input
abcd
aaaa
ababab
.
Sample 1 Output
1
4
3