真心不想去考证为啥这样,就这样吧!!!
题意:http://acm.hdu.edu.cn/showproblem.php?pid=4320
问a进制下的小数能否转化为b进制下的小数。
解:
检查A中的质因子 是否都在 B中被包含。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
long long a,b,c;
long long gcd(long long x, long long y){
if(y == 0)
return x;
return gcd(y, x % y);
}
int main(){
int T;
scanf("%d",&T);
for(int ca = 1; ca <= T; ca ++){
scanf("%I64d%I64d",&a,&b);
printf("Case #%d: ",ca);
c = gcd(a,b);
while(c > 1){
a /= c;
c = gcd(a,b);
}
if(a == 1) puts("YES");
else puts("NO");
}
return 0;
}