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. Python 入門語法和類型(转载学习)

    http://www.cnblogs.com/mcdou/archive/2011/08/02/2125016.html Python的设计目标之一是让源代码具备高度的可读性.它设计时尽量使用其它语言 ...

  2. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindowX 02

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindowX 02 procedure TForm1.Button1Click(Sender: TObject);var img : H ...

  3. 实施费用也能DIY--走出软件作坊:三五个人十来条枪 如何成为开发正规军(九)[转]

    上次咱们讲完了开发费用的计算,很多人在后面跟帖在那里算费用. 有人说:你把程序员都不当人,94天,一天都不休息啊. 我想答曰:94天,是工作时间.不算双休日在里面.也就是说,实际的开发周期长度是94+ ...

  4. 一个fork()系统调用的问题

    转载:http://coolshell.cn/articles/7965.html 题目:请问下面的程序一共输出多少个“-”? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  5. SqlServer nvarchar中的中文字符匹配,更改SqlServer实例和数据库排序规则的办法

    我们都知道在SqlServer中的nvarchar类型可以完美的存储诸如中文这种unicode字符,但是我们会发现有时候查询语句去查询nvarchar列的时候查不出来. 为什么nvarchar类型有时 ...

  6. 【DP水题】投票问题(二)

    投票问题(一) [试题描述] 欧阳文和欧阳武竞选学联主席,汪梁森负责唱票,共有m+n张,结果欧阳文获胜,已知欧阳文和欧阳武分别获得 m 张票和 n 张票(m>n).现在请你计算在唱票过程中欧阳文 ...

  7. unix

    BSD (Berkeley Software Distribution,伯克利软件套件)是Unix的衍生系统,在1977至1995年间由加州大学伯克利分校开发和发布的.历史上, BSD曾经被认为是UN ...

  8. python核心编程学习记录之数字

    仅用于整数的操作

  9. symfony中twig的模板过滤器

    过滤器 变量可以被过滤器修饰.过滤器和变量用(|)分割开.过滤器也是可以有参数的.过滤器也可以被多重使用. 通用过滤器 date过滤器 1.1版本新增时区支持,1.5版本增加了默认的日期格式.格式化时 ...

  10. cocos2dx lua bug之module 'lsqlite3' not found

    05-27 15:41:01.360: D/cocos2d-x debug info(7261): [LUA-print] -------------------------------------- ...