-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10298.cpp
59 lines (50 loc) · 1.29 KB
/
10298.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
static inline bool cmp(char *x, char *y, int len)
{
int i;
for (i = 0; i < len; ++i)
if (x[i] != y[i]) return false;
return true;
}
int main(void)
{
bool flag;
char str[1000005];
int len, i, j, max, seg;
while (true) {
scanf("%s", str);
if (str[0] == '.')
break;
else
len = strlen(str);
flag = true;
for (j = 1; j < len && flag; ++j)
flag &= (str[0] == str[j]);
if (flag)
max = len;
else {
max = 1;
for (i = 2; i <= (int)sqrt(len); ++i)
if (len % i == 0) {
flag = true;
for (j = i; j < len && flag; j += i)
flag &= cmp(str, str + j, i);
if (flag) {
max = len / i;
break;
}
seg = len / i;
flag = true;
for (j = seg; j < len && flag; j += seg)
flag &= cmp(str, str + j, seg);
if (flag) max = i;
;
}
}
printf("%d\n", max);
}
return 0;
}