hdu 4320 Arcane Numbers 1(小数进制转化后是否有限位)

Arcane Numbers 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2380    Accepted Submission(s): 758


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.
 

Sample Input
  
  
3 5 5 2 3 1000 2000
 

Sample Output
  
  
Case #1: YES Case #2: NO Case #3: YES
 

Author
BJTU
 

Source
 

Recommend
zhoujiaqi2010
 

题意:将a进制的有限小数转化为b进制的小数是否是有限位的

题解:若b有a的所有质因子,则可以,反之不可以


#include<stdio.h>
long long gcd(long long a,long long b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    int t,cas=1;
    long long x,y,temp;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&x,&y);
        temp=x;
        while(temp>1)
        {
            temp=gcd(x,y);
            x/=temp;
        }
        if(x>1) printf("Case #%d: NO\n",cas++);
        else printf("Case #%d: YES\n",cas++);
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值