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.

InputThe first line contains a single integer T, the number of test cases. 
For each case, there’s a single line contains A and B. 
OutputFor 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 关键:只要B中包含A中的所有的素因子,就一定能找到h,是两种进制之间可以实现相互转换。

利用 二进制小数转化成十进制小数的方法。

假设一个A进制小数为 a,那么转化的时候,有个过程需要不断地重复 a =(a*B)% 1。(这里规定 %1 表示去除整数部分)(先将B转化成A进制,再放入此公式)

(除去的整数部分,转化成B进制,即依次为B的小数部分)

直到a 等于 0。即转化成功。

若永远无法使 a 等于 0,即无法转化。

那么在什么情况下,能够转化成功呢?

假若 a的小数部分,最右端为一个非0数字(介于 1 ~ A-1之间)。

我们可以从中随便找一个数字s ,最坏的情况是 s 与 A 互质。

而上面式子可以写成 :$(a{\rm{ *}}B*{\rm{ }}B{\rm{ }}*{\rm{ }} \ldots {\rm{ }}*{\rm{ }}B\;)\% {\rm{ }}1 = 0$

首先就需要满足(注意这里s、B均是A进制整数,并且是正常%A):$(s*B*B* \ldots *B)\% A = 0$

很容易得出,上式其实是需要满足 :$(B*B* \ldots *B)\% A = 0$

  所以求的就是 A 的所有质因子,B是否含有?   若含有,则能转化。

那么用一个技巧 求 gcd ,很简单就能解决此问题。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
while(b){
ll temp=b;
b=a%b;
a=temp;
}
return a;
}
int main(){
ll t;
scanf("%lld",&t);
for(int i=;i<=t;i++){
ll a,b;
scanf("%lld%lld",&a,&b);
ll c=gcd(a,b);
while(c>){ //这种处理方式很漂亮
a/=c;
c=gcd(a,b);
}
if(a==){
printf("Case #%d: YES\n",i);
}else{
printf("Case #%d: NO\n",i);
}
}
}

Arcane Numbers 1的更多相关文章

  1. 2012 #3 Arcane Numbers

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

  2. HDU 4320 Arcane Numbers 1 (数论)

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

  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. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. P3506 [POI2010]MOT-Monotonicity 2

    题目 P3506 [POI2010]MOT-Monotonicity 2 第一次切掉没题解的题\(qwq\) 做法 首先确定\(a_i\)的位置后显然就能确定\(a_{i+1}\)的位置,建一棵权值线 ...

  2. hid_info函数分析

    昨天博文<linux下无线鼠标驱动执行流程>中有一行输出信息很让我迷惑,如下所示: [ :1D57: Mouse [HID Wireless Mouse HID Wireless Mous ...

  3. POJ 3070 矩阵mob

    . 矩阵高速幂想法与快速幂相同 #include<iostream> #include<cstdio> #include<cstring> #define MOD ...

  4. HDU1232 畅通工程,并查集

    这里要补充一些知识点,并查集三操作 1.找到父节点递归写法int Findf(int x){ if(father[x]!=x) father[x]=Findf(father[x]); return f ...

  5. log4net性能小探

    初步测试了Log4性能.Appender架构如下. 一般客户端,使用FileAppender,把Log记录在本地磁盘. <lockingModel type="log4net.Appe ...

  6. EntityFramework 学习 一 Lazy Loading 1

    延迟加载:延迟加载相关的数据 using (var ctx = new SchoolDBEntities()) { //Loading students only IList<Student&g ...

  7. 算法(Algorithms)第4版 练习 1.5.8

    假设原id数组: 0 1 1 4 4 8 6 1 8 0 输入p = 5, q = 7 则输出结果会出错,最终为: 0 1 1 4 4 1 6 1 8 0 因为当id[p](id[5] = 8)被赋值 ...

  8. DIV+CSS IE6/IE7/IE8/FF兼容问题大全

    1. [代码][CSS]代码 1, FF下给 div 设置 padding 后会导致 width 和 height 增加, 但IE不会.(可用!important解决) 2, 居中问题. 1).垂直居 ...

  9. Linux-MySQL主从配置

    1. MySQL主从原理以及应用场景MySQL的Replication原理非常简单,总结一下:每个从仅可以设置一个主.主在执行sql之后,记录二进制log文件(bin-log).从连接主,并从主获取b ...

  10. L106 Three things we learned from day one at the World Cup

    Hosts Russia got the World Cup off to a flying start by hammering Saudi Arabia 5-0 in the opening ga ...