-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeforces-182D.cc
51 lines (40 loc) · 959 Bytes
/
Codeforces-182D.cc
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <string>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
vector <string> s(2);
cin >> s[0] >> s[1];
if(s[0].length() > s[1].length()){
swap(s[0], s[1]);
}
int ans = 0;
int n = s[0].length();
int m = s[1].length();
for(int i = 0; i < n; i++){
if(n % (i + 1) == 0 && m % (i + 1) == 0){
bool valid = true;
for(int j = 0; j < n; j += (i + 1)){
if(!valid) break;
if(s[0].substr(j, i + 1) != s[0].substr(0, i + 1)){
valid = false;
}
}
for(int j = 0; j < m; j += (i + 1)){
if(!valid) break;
if(s[1].substr(j, i + 1) != s[0].substr(0, i + 1)){
valid = false;
}
}
valid &= s[1].substr(0, i + 1) == s[0].substr(0, i + 1);
ans += valid;
}
}
cout << ans;
return 0;
}