Arcane Numbers 1

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; long long gcd(long long a,long long b)
{
if(a<b)
return gcd(b,a);
else if(b==)
return a;
else
return gcd(b,a%b);
} int main()
{
int T,ca=;
long long A,B;
int i,j,k,flg;
scanf("%d",&T);
while(T--)
{
scanf("%I64d %I64d",&A,&B);
long long C=gcd(A,B),D;
A=A/C,B=B/C;
flg=;
if(B>)
{
while()
{
if(B==)
break;
D=gcd(B,C);
if(D==)
{
flg=;
break;
}
B=B/D;
}
}
if(A>)
{
while()
{
if(A==)
break;
D=gcd(A,C);
if(D==)
{
flg=;
break;
}
A=A/D;
}
}
if(flg==)
printf("Case #%d: YES\n",ca);
else
printf("Case #%d: NO\n",ca);
ca++;
}
return ;
}

2012 #3 Arcane Numbers的更多相关文章

  1. HDU 4320 Arcane Numbers 1 (数论)

    A - Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  2. Arcane Numbers 1

    Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...

  3. HDU 4320 Arcane Numbers 1 (质因子分解)

    题目:传送门. 题意:将一个A进制下的有限小数转化为B进制看是否仍为有限小数. 题解:一个A进制的小数可以下次 左移动n位变成A进制整数然后再将其转化为B进制即可 即B^m/A^n要整除,因此A的质因 ...

  4. HDU 4320 Arcane Numbers 1(质因子包含)

    http://acm.hdu.edu.cn/showproblem.php?pid=4320 题意: 给出A,B,判断在A进制下的有限小数能否转换成B进制下的有限小数. 思路: 这位博主讲得挺不错的h ...

  5. 数论(GCD) HDOJ 4320 Arcane Numbers 1

    题目传送门 题意:有一个A进制的有限小数,问能否转换成B进制的有限小数 分析:0.123在A进制下表示成:1/A + 2/(A^2) + 3 / (A^3),转换成B进制就是不断的乘B直到为0,即(1 ...

  6. HDU 4321 Arcane Numbers 2

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4321 ----------------------------------------------- ...

  7. 2012多校3.A(用O(log(n))判断b^k % a == 0)

    Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  8. 59. 总结篇:数组中N(n=1,2,3)个只出现一次的数字[find N numbers which appear only once in array]

    [本文链接] http://www.cnblogs.com/hellogiser/p/find-n-numbers-which-appear-only-once-in-array.html [题目] ...

  9. Overview of Form Control Types [AX 2012]

    Overview of Form Control Types [AX 2012] Other Versions 0 out of 1 rated this helpful - Rate this to ...

随机推荐

  1. 夺命雷公狗---2016-linux---3之目录一般作用

    最好文件还是存放在自己的home目录下 建议:在很多时候如果需要系统备份最好去备份boot和etc这两个目录

  2. javascript中字符串格式json如何转化成json对象

    什么是JSON JSON(JavaScript Object Notation)是一种优美的JavaScript对象创建方法.JSON也是一种轻量级数据交换格式.JSON非常易于人阅读与编写,同时利于 ...

  3. ubuntu遇到的命令

    sudo passwd root这个命令是给root用户设定密码.su root切换到root用户.sudo cp 文件 /var/www移动文件到一个目录unzip xxx.zip解压zip文件mk ...

  4. 关于更改MYECLIPSE JS 代码背景颜色

    白色的背景,看花了眼,你想改一下编辑器的背景颜色,移步这里就可以了. 这时你高兴的打开编辑器,发现颜色确实变了,但是当你打开有JS的JSP时,你碉堡了,发现JS的背景颜色还是默认的, 看着让人纠结,好 ...

  5. 160922、配置:spring通过profile或@profile配置不同的环境(测试、开发、生产)

    一.配置环境 applicationContext.xml中添加下边的内容(develop:开发环境,production:生产环境,test:测试环境) 注意:profile的定义一定要在文档的最下 ...

  6. 在使用Myeclipse时,用Tomcat添加部署项目的时候报错,或启动tomcat报错

    the selected server is enabled,but is not configured properly.deployment to it will not be permitted ...

  7. Dynamics AX 2012 R2 在报表上显示和打印条码

        AX中有对条码操作的封装,用其生成BarCodeString类型的值,再配合barcode128字体,即可在显示出条码.     废话不说,上代码. BarcodeCode128 barCod ...

  8. Dynamics AX 2012 R2 Service Middle Tier WCF WCF转发

    参考了蒋金楠老师08年的文章.好吧,那时候我才大二.大三,大神果然是大神. http://www.cnblogs.com/artech/archive/2008/09/01/1280939.html ...

  9. java map 遍历

    转自http://rain-2372.iteye.com/blog/1615615 package com.spring.test_B11_aop1; import java.util.HashMap ...

  10. 【PHP设计模式 02_JieKou.php】面向接口开发

    <?php /** * [面向接口开发] * */ header("Content-type: text/html; charset=utf-8"); /*共同接口--连接数 ...