http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1003
#include <stdio.h> #define bool int #define false 0 #define true 1 bool aTrue, bTrue; int judge(int m, int n, int p) { if (aTrue) return 0; if (m == 1 && n == 1) { aTrue = true; return 0; } if (n == 1) bTrue = true; while (p > 1) { if (m%p == 0) judge(m/p, n, p - 1); if (n%p == 0) judge(m, n/p, p - 1); p--; } return 0; } int main() { int a, b; while(scanf("%d%d", &a, &b) != EOF) { if (a < b) { int temp = a; a = b; b = temp; } aTrue = bTrue = false; judge(a, b, 100); if (!aTrue && bTrue) printf("%d\n", b); else printf("%d\n", a); } return 0; }