2012 #3 Arcane Numbers

來源:互聯網
上載者:User

標籤:

Arcane Numbers 1Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64uSubmit Status Practice HDU 4320

Description

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

35 52 31000 2000  

Sample Output

Case #1: YESCase #2: NOCase #3: YES
 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5  6 long long gcd(long long a,long long b)  7 {  8     if(a<b)  9         return gcd(b,a); 10     else if(b==0) 11         return a; 12     else13         return gcd(b,a%b); 14 }15 16 int main()17 {18     int T,ca=1;19     long long A,B;20     int i,j,k,flg;21     scanf("%d",&T);22     while(T--)23     {24         scanf("%I64d %I64d",&A,&B);25         long long C=gcd(A,B),D;26         A=A/C,B=B/C;27         flg=1;28         if(B>1)29         {30             while(1)31             {32                 if(B==1)33                     break;34                 D=gcd(B,C);35                 if(D==1)36                 {37                     flg=0;38                     break;39                 }40                 B=B/D;41             }42         }43         if(A>1)44         {45             while(1)46             {47                 if(A==1)48                     break;49                 D=gcd(A,C);50                 if(D==1)51                 {52                     flg=0;53                     break;54                 }55                 A=A/D;56             }57         }58         if(flg==1)59             printf("Case #%d: YES\n",ca);60         else61             printf("Case #%d: NO\n",ca);62         ca++;63     }64     return 0;65 }
View Code

 

2012 #3 Arcane Numbers

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.