-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1003.cpp
More file actions
61 lines (56 loc) · 700 Bytes
/
1003.cpp
File metadata and controls
61 lines (56 loc) · 700 Bytes
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
60
61
#include <iostream>
using namespace std;
bool alldone,bdone;
void DFS(int a, int b, int num)
{
if(alldone)
{
return;
}
if(a == 1 && b ==1)
{
alldone = true;
return;
}
if(b == 1)
{
bdone = true;
}
while(num > 1)
{
if(a%num == 0)
{
DFS(a/num, b, num-1);
}
if(b%num == 0)
{
DFS(a, b/num, num-1);
}
num--;
}
return;
}
int main()
{
int a,b,temp;
while(cin >> a >> b)
{
if(a < b)
{
temp = a;
a = b;
b = temp;
}
alldone = false;
bdone = false;
DFS(a,b, 100);
if(!alldone && bdone)
{
cout << b << endl;
}
else
{
cout << a << endl;
}
}
}