-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoj 1003.cpp
55 lines (49 loc) · 951 Bytes
/
zoj 1003.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
#include <stdio.h>
#include <math.h>
int flag_a=0,flag_b=0;
void compare(int *a,int *b)
{
int temp;
if(*b>*a)
{
temp=*a;
*a=*b;
*b=temp;
}
}
void DFS(int a,int b,int tmp)
{
int i;
if(tmp>100)
return;
if(a==1&&b==1)
flag_a=1;
if(b==1)
flag_b=1;
for(i=tmp;i<=100;i++)
{
if(a%i==0)
DFS(a/i,b,i+1);
if(b%i==0)
DFS(a,b/i,i+1);
}
}
void run(int a,int b)
{
flag_a=flag_b=0;
DFS(a,b,2);
if(flag_a==0&&flag_b==1)
printf("%d\n",b);
else
printf("%d\n",a);
}
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
{
compare(&a,&b);
run(a,b);
}
return 0;
}