2012 Multi-University Training Contest 3:Arcane Numbers 1
2012-08-13 19:43
561 查看
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.
Output
For each case, output “NO” if Vance will win the game. Otherwise, print “YES”. See Sample Output for more details.
SampleInput
SampleOutput
Author
Vance and Shackler
//题意:问一个A进制下的有限小数嫩否在B进制下也是有限小数。
//一个小数x转换为A进制就是不断的除以A,可以记为x*A^(-p) 。 而这个有限小数要转化为 B进制下的小数,按进制转换规则就要不断乘以B,直到得到一个整数,最后将这个整数做B进制处理然后小数点向右移m位,m为乘以B的次数。 所以,A进制下的小数x*A(-p)一直乘以B后必须为整数,即x*(A^(-p))*(B^q)为整数,则要求B^q%A^p==0。其中p,q可以为任意值。 显然要求A的所有质因子都必须被B包含。
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.
SampleInput
3 5 5 2 3 1000 2000
SampleOutput
Case #1: YES Case #2: NO Case #3: YES
Author
Vance and Shackler
//题意:问一个A进制下的有限小数嫩否在B进制下也是有限小数。
//一个小数x转换为A进制就是不断的除以A,可以记为x*A^(-p) 。 而这个有限小数要转化为 B进制下的小数,按进制转换规则就要不断乘以B,直到得到一个整数,最后将这个整数做B进制处理然后小数点向右移m位,m为乘以B的次数。 所以,A进制下的小数x*A(-p)一直乘以B后必须为整数,即x*(A^(-p))*(B^q)为整数,则要求B^q%A^p==0。其中p,q可以为任意值。 显然要求A的所有质因子都必须被B包含。
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<queue> #include<stack> #include<map> #include<vector> #include<algorithm> #include<ctime> using namespace std; #define maxn 1000000 #define LL __int64 bool x[maxn+10]; int prime[maxn+10],num=0; void Init() { int i,tmp; memset(x,false,sizeof(x)); x[0]=x[1]=true; for(i=2;i<=maxn;i++) if(!x[i]) { prime[++num]=i; tmp=i*2; while(tmp<=maxn) { x[tmp]=true; tmp+=i; } } } int main() { Init(); int T,t=0,i; LL n,m; LL A[100]; scanf("%d",&T); while(T--) { int cnta=0; scanf("%I64d%I64d",&n,&m); printf("Case #%d: ",++t); if(n==m) { puts("YES"); continue; } for(i=1;i<=num&&(LL)prime[i]*prime[i]<=n;i++) if(n&&n%prime[i]==0) { A[++cnta]=prime[i]; while(n&&n%prime[i]==0) n/=prime[i]; } if(n>1) A[++cnta]=n; bool flag=true; for(i=1;i<=cnta;i++) if(m%A[i]!=0) { flag=false; break; } printf("%s\n",flag?"YES":"NO"); } return 0; }
相关文章推荐
- HDU 6168 - Numbers 水题 2017 Multi-University Training Contest - Team 9
- 2012 Multi-University Training Contest 2 [hdu4310~4319]
- 2012 Multi-University Training Contest 3
- 2012 Multi-University Training Contest 4[hdu4331~4339]
- 2012 Multi-University Training Contest 5:History repeat itself
- hdu 4391 Paint The Wall 线段树 +优化 2012 Multi-University Training Contest 10 )
- HDU 4340 Capturing a country 2012 Multi-University Training Contest 5
- HDU4355-Party All the Time-三分法(模板)-2012 Multi-University Training Contest 6
- 2012 Multi-University Training Contest 5:Mark the Rope
- 2012 Multi-University Training Contest 6
- hdu 4355 Party All the Time (2012 Multi-University Training Contest 6 ) 三分搜索
- 2012 Multi-University Training Contest 9 / hdu4389
- 2012 Multi-University Training Contest 5 Problem F Permutation(HDU4345)
- 2012 Multi-University Training Contest 2 Matrix
- hdu 4317 Unfair Nim(状态压缩DP)——2012 Multi-University Training Contest 2
- 【2017 Multi-University Training Contest - Team 9】Numbers
- 2012 Multi-University Training Contest 6[hdu4350~4359]
- 2012 Multi-University Training Contest 6
- 2012 Multi-University Training Contest 7
- hdu 4396 More lumber is required (二维最短路 应用 2012 Multi-University Training Contest 10 )