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. Kattis - flippingcards 【并查集】

    题意 给出 N 对 数字 然后 每次从一对中 取出一个数字 判断 能否有一种取出的方案 取出的每个数字 都是不同的 思路 将每一对数字 连上一条边 然后 最后 判断每一个连通块里面 边的个数 是否 大 ...

  2. Spark MLlib框架详解

    1. 概述 1.1 功能 MLlib是Spark的机器学习(machine learing)库,其目标是使得机器学习的使用更加方便和简单,其具有如下功能: ML算法:常用的学习算法,包括分类.回归.聚 ...

  3. hd acm1013

    Problem Description(数根) The digital root of a positive integer is found by summing the digits of the ...

  4. dbgrid,datasoure,ClientDataSet的简单应用

    dbgrid是用来在界面上显示数据的,需要连接源dbgrid1.datasource := datasource1; datasource:作为dbgrid,clientDataset的连接桥梁,需要 ...

  5. jquery获取点击标签内的子标签内容和值实例

    今天有点累了,就不多做其他的描述解释.在插入的代码里相关解释也都有. <!--<%@ page language="java" import="java.ut ...

  6. java客户端文件的上传和下载

    java客户端文件的上传和下载 //上传 public JTable upload(String id){ JTable table=new JTable(); System.out.println( ...

  7. Idea_学习_01_Idea激活

    一.激活—激活码 下载地址:官网 1.注册码 http://idea.lanyus.com/ 二.激活—license server 1. (推荐) 弹窗中选择最后一个页面license server ...

  8. php判断是否是微信浏览器

    php判断是否是微信浏览器 直接上代码: <?PHP function is_wechat_browser(){ $user_agent = $_SERVER['HTTP_USER_AGENT' ...

  9. 用截取的部分图像创建新图像--关于cvGetSubRect,cvGetImage的用法

    CvMat* cvGetSubRect(const CvArr* arr, CvMat* submat, CvRect rect)可以把截取图像中需要的区域存入矩阵.把IplImage *传给arr, ...

  10. CRtmpServer

    1.  前言 crtmpserver是一个由C++语言编写的开源的RTMP流媒体服务器,官方网站是www.rtmpd.com 2.   CRtmpServer编译   2.1.  Win7+Vs201 ...