1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<math.h>
4 #include<string.h>
5
6 int ascore, bscore;
7
8 int DFS(int m, int n, int p)
9 {
10 if(ascore == 1) return 0;
11 if(m==1 && n==1)
12 {
13 bscore = 1;
14 ascore = 1;
15 return 0;
16 }
17
18 if(n == 1) bscore = 1;
19
20 while (p > 1)
21 {
22 if(m%p == 0) DFS(m/p, n, p-1);
23 if(n%p == 0) DFS(m, n/p, p-1);
24 p--;
25 }
26
27 return 0;
28 }
29
30 int main()
31 {
32 int a, b, temp;
33
34 while(scanf("%d%d",&a,&b) != EOF)
35 {
36
37 if(a < b)
38 {
39 temp = a;
40 a = b;
41 b = temp;
42 }
43 ascore = 0; bscore = 0;
44
45 DFS(a, b, 100);
46 if(bscore && !ascore)
47 printf("%d\n", b);
48 else
49 printf("%d\n", a);
50
51 }
52
53 return 0;
54 }
55
56
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步