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. 【crunch bang】中文美化

    原文连接:http://edyfox.codecarver.org/html/debian_testing_chinese.html 中文字体美化是个很讨厌的事情,无数初学者在这里面浪费了无数时间,做 ...

  2. Centos安装wine等组件的问题

    linux下安装wine可以从源码编译安装,但一般都觉得麻烦,所以尽量利用yum进行安装,解决很多包的依赖关系. 首先安装一个epelrpm -ivh http://dl.fedoraproject. ...

  3. Ubuntu 安装 “宋体,微软雅黑,WPS Office的symbol、wingdings、wingdings 2、wingdings 3、webding字体,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体(转)

    Windows平台下,"宋体"."微软雅黑"."Courier New(编程字体)"用的比较多,看的也习惯了.那如何在 Ubuntu下也安装 ...

  4. 将UTF8编码的3字节中英文转成2字节中英文.

    1. 首先要考虑将String转成一个bytes的数组, 每个汉字是3个bytes, 英文或者标点是1个byte. 2. 然后去判断一下每一个byte的前面几个bit, 看下面的表, 1个byte的字 ...

  5. centos7重启rsyslog服务|centos7重启syslog服务

    centos7重启rsyslog服务: systemctl restart rsyslog 使用:(killall无效) killall -HUP rsyslog

  6. 完整学习git五git重置

    git重置命令的一个用途就是修改引用的游标指向 1查看git操作日志 git reflog 2查看当前head游标的指向 cat .git/refs/heads/master 3重置和跳转 git r ...

  7. oracle nvl和nvl2的区别

    一直用oracle nvl函数,最近发现还有一个nvl2函数: nvl(a,b) 如果a不为null 则返回a,如果a为null则返回b; nvl2(a,b,c) ,如果a不为null 则返回b,如果 ...

  8. c#对话框

    OpenFileDialog open = new OpenFileDialog();//创建对话框 open.InitialDirectory = @"C:\Documents and S ...

  9. Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏

    Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...

  10. JAVA基础知识之网络编程——-使用MutilcastSocket实现多点广播

    IP多点广播原理 设置一组特殊网络地址作为多点广播地址,每一个多点广播地址都被看作一个组,当客户需要发送和接受信息时,加入到该组即可. IP协议为多点广播提供了一批特殊的IP地址,范围是224.0.0 ...