gcd(1)

Arcane Numbers 1

Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers". The game is pretty simple, Vance writes down a finite decimal under base A, and then Shackler translates it under base B. If Shackler can translate it into a finite decimal, he wins, else it will be Vance’s win. Now given A and B, please help Vance to determine whether he will win or not. Note that they are playing this game using a mystery language so that A and B may be up to 10^12.
 

Input

The first line contains a single integer T, the number of test cases.
For each case, there’s a single line contains A and B.
 

Output

For each case, output “NO” if Vance will win the game. Otherwise, print “YES”. See Sample Output for more details.
 

Sample Input

3
5 5
2 3
1000 2000

Sample Output

Case #1: YES
Case #2: NO
Case #3: YES
#include<cstdio>
#define ll __int64
using namespace std;
ll gcd(ll a,ll b){
    return b ?gcd(b,a%b):a;
}
int main (){
    ll a,b;
    int t,cas = 0;
    scanf("%d",&t);
    while(t--){
        scanf("%I64d%I64d",&a,&b);
        while(1){
            ll temp = gcd(a,b);
            a/=temp;
            if(temp==1)break;
        }
        printf("Case #%d: ",++cas);
        if(a!=1)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

 

posted @ 2015-08-25 21:33  Tobu  阅读(141)  评论(0)    收藏  举报