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. 1django 视图与网址

    创建一个项目,名字叫mysite django-admin startproject mysite(项目名) 成功后,看到如下样式 mysite ├── manage.py └── mysite ├─ ...

  2. interface -- 接口类

    <?php /** *为了声明接口,需要使用关键字interface *interface IExampleInterface {} *说明(大多数开发人员选择在节后名称前加上大写字母I作为前缀 ...

  3. HDU - 3081 Marriage Match II 【二分匹配】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...

  4. spring-cloud 实现更新配置不用重启服务 @FreshScope

    继续前面搭建的spring cloud. 这里是基于rabbitMQ搭建的,首先需要在电脑上安装rabbitMQ. 在client端和server端分别加上如下依赖 compile group: 'o ...

  5. java面试_数据库

    1.group by 根据表里的字段名分类,相同字段名只显示一行记录,通常与聚集函数max.min合用选择最大值最小值,或者与having合用筛选,结果按照group by的字段排序 例:select ...

  6. Referrer-Policy常见属性

    Referrer-Policy(来源协议)用来规定什么情况下显示Referer字段及refer字段内显示多少信息. 备注: referer实际上是对referrer的误写,因为写错的人多了也就正确了. ...

  7. 《python基础教程(第二版)》学习笔记 文件和素材(第11章)

    <python基础教程(第二版)>学习笔记 文件和素材(第11章) 打开文件:open(filename[,mode[,buffering]]) mode是读写文件的模式f=open(r' ...

  8. perl常用字符串函数

    1.$position = index(string,substring,skipchars): 该函数返回子串substring在字符串string中的位置,如果不存在,则返回-1:参数skipch ...

  9. LINQ 学习路程 -- 查询操作 ThenBy & ThenByDescending

    IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } ...

  10. EntityFramework 学习 一 实体类型

    我们为已存在的数据库创建EDM,EDM包含与数据库中表对应的实体.EF中有两种实体类型 POCO entity dynamic proxy entity POCO Entity (Plain Old ...