http://acm.hdu.edu.cn/showproblem.php?pid=4320
/* 公式:两个进制能相互转化,那么这两个进制的最小因数相同 */ /************************************************ * Author :Powatr * Created Time :2015-8-25 14:49:53 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; long long a, b; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a%b); } int main() { int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas++){ scanf("%I64d%I64d", &a, &b); long long c = gcd(a, b); long long d; a /= c, b /= c; int flag = 1; while(1){ if(b == 1) break; d = gcd(b, c); if(d == 1){ flag = 0; break; } b /= d; } while(1){ if(a == 1) break; d = gcd(a, c); if(d == 1){ flag = 0; break; } a /= d; } printf("Case #%d: %s ", cas, flag == 1 ? "YES" : "NO"); } return 0; }