Arcane Numbers 1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1468 Accepted Submission(s): 466
Problem 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.
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
Author
Vance and Shackler
Source
Recommend
zhoujiaqi2010
//不懂意思、到网上查了下意思、就是问A的因子数B里面是否都有
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <cmath> #include <queue> #include <vector> #define N 1000000 using namespace std; bool h[1000001]; int rc[100000]; int cnt; void set() { int i,j,k=1; for(i=4;i<N;i+=2) h[i]=1; for(i=3;i<1000;i+=2) if(!h[i]) { for(j=i*i;j<N;j+=i) h[j]=1; } for(i=3;i<N;i+=2) if(!h[i]) rc[k++]=i; rc[0]=2;rc[k]=1000000000; } int main() { set(); int T,t=1; __int64 A,B; int i,k; __int64 c[22];//卡这里好久,A可能是超过int范围的素数、所以、悲剧 bool b; scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&A,&B); int temp=sqrt(double(A)); for(k=i=0;rc[i]<=temp;i++) { b=0; while(A%rc[i]==0) { b=1; A/=rc[i]; } if(b) c[k++]=rc[i]; if(A==1) break; } if(A!=1) c[k++]=A; for(i=0;i<k;i++) if(B%c[i]) break; printf("Case #%d: ",t++); printf(i==k?"YES\n":"NO\n"); } return 0; }
//再插段好点的代码
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <cmath> #include <queue> #include <vector> #define N 1000000 using namespace std; bool h[1000001]; int rc[100000]; int cnt; void set() { int i,j,k=1; for(i=4;i<N;i+=2) h[i]=1; for(i=3;i<1000;i+=2) if(!h[i]) { for(j=i*i;j<N;j+=i) h[j]=1; } for(i=3;i<N;i+=2) if(!h[i]) rc[k++]=i; rc[0]=2;rc[k]=1000000000; } int main() { set(); int T,t=1; __int64 A,B; int i,k; int c[22]; bool b; scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&A,&B); int temp=sqrt(double(A)); for(b=1,i=0;rc[i]<=temp;i++) { if(A%rc[i]==0) { if(B%rc[i]!=0) { b=0; break; } while(A%rc[i]==0) A/=rc[i]; } } if(A!=1&&(B%A)!=0) b=0; printf("Case #%d: ",t++); if(b) printf("YES\n"); else printf("NO\n"); } return 0; }