A - 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

对于A进制的一个数,先将其左移N位使得其成为一个整数,然后再将这个整数化为B进制的一个数,

然后我们只需要考虑这个数是否能够整除A^N即可(因为我们前面左移了N位),我可以将B进制的

这个数先进行左移无限位,那么当有A^N 整除 B^INF 时我们就可以将这个除尽,然后我们再将B

右移INF位便可以了。

这里就把问题转化为了A^N能够整除B^INF进制了,进一步我们可以得到B包含所有A的质因子便为判定条件了。

#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
const int maxn=;
bool isprime[maxn];
int prime[maxn];
using namespace std;
int i,j,k=;
void pr()
{
for(i=;i<=maxn;i++)
{
if(!isprime[i])
{
for(j=i+i;j<=maxn;j=j+i)
isprime[j]=true;
prime[k++]=i;
}
}
}
int main()
{
pr();
int t,c=;
bool flag=true;
long long a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&a,&b);
flag=true;
for(i=;i<k&&prime[i]<=a;i++)
{
if(a%prime[i]==)
{
if(b%prime[i]!=)
{
flag=false;
break;
}
}
while(a%prime[i]==)
a/=prime[i];
}
if(b%a!=)
flag=false;
if(flag)
cout<<"Case #"<<c++<<": YES"<<endl;
else
cout<<"Case #"<<c++<<": NO"<<endl;
}
return ;
}

HDU 4320 Arcane Numbers 1 (数论)的更多相关文章

  1. HDU 4320 Arcane Numbers 1(质因子包含)

    http://acm.hdu.edu.cn/showproblem.php?pid=4320 题意: 给出A,B,判断在A进制下的有限小数能否转换成B进制下的有限小数. 思路: 这位博主讲得挺不错的h ...

  2. HDU 4320 Arcane Numbers 1 (质因子分解)

    题目:传送门. 题意:将一个A进制下的有限小数转化为B进制看是否仍为有限小数. 题解:一个A进制的小数可以下次 左移动n位变成A进制整数然后再将其转化为B进制即可 即B^m/A^n要整除,因此A的质因 ...

  3. 数论(GCD) HDOJ 4320 Arcane Numbers 1

    题目传送门 题意:有一个A进制的有限小数,问能否转换成B进制的有限小数 分析:0.123在A进制下表示成:1/A + 2/(A^2) + 3 / (A^3),转换成B进制就是不断的乘B直到为0,即(1 ...

  4. HDU 4321 Arcane Numbers 2

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4321 ----------------------------------------------- ...

  5. 2012 #3 Arcane Numbers

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

  6. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  7. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  8. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  9. Arcane Numbers 1

    Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...

随机推荐

  1. 初识Continuation

    本文来自网易云社区 作者:陆艺 上学时看了SICP之后就对scheme这个看上去比较古怪的语言产生了兴趣. 虽然书里并没有涉及scheme太多语法以及语言上特性的一些东西, 作为一个喜欢折腾的人, 手 ...

  2. 「日常训练」 Soldier and Number Game (CFR304D2D)

    题意 (Codeforces 546D) 给定一个数x=a!b!" role="presentation">x=a!b!x=a!b!的形式,问其中有几个质因数. 分 ...

  3. linux学习总结---web前端③

    css3: border-radius opacity: transform: 旋转 rotate 平移translate 缩放scale 扭曲skew transition:转变 强调:开始和结束 ...

  4. LeetCode 2——两数相加

    1. 题目 2. 解答 循环遍历两个链表 若两个链表都非空,将两个链表结点的值和进位相加求出和以及新的进位 若其中一个链表为空,则将另一个链表结点的值和进位相加求出和以及新的进位 然后将每一位的和添加 ...

  5. 今日头条 2018 AI Camp 6 月 2 日在线笔试编程题第二道——两数差的和

    题目 给 n 个实数 a_1, a_2 ... a_n, 要求计算这 n 个数两两之间差的绝对值下取整后的和是多少. 输入描述 第一行为一个正整数 n 和一个整数 m.接下来 n 行,第 i 行代表一 ...

  6. BST插入与查找

    B树: 二叉查找树,所有左节点都比父节点要小,所有右节点都比父节点要大.查找,插入的时间复杂度为O(logn) public class BTreeTest { public static int[] ...

  7. OpenCV膨胀和腐蚀示例代码

    #include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...

  8. 在es中用scroll查询与completableFuture

    一般而言,es返回数据的上限是10000条,如果超过这个数量,就必须使用scroll查询. 所谓scroll查询就类似DBMS中的游标,或者快照吧,利用查询条件,在第一次查询时,在所有的结果上形成了一 ...

  9. 【bzoj1260】[CQOI2007]涂色paint 区间dp

    题目描述 给出一个序列,每次可以给一段染成同一种颜色,问最少要染多少次能够染成给定方案. 输入 输入仅一行,包含一个长度为n的字符串,即涂色目标.字符串中的每个字符都是一个大写字母,不同的字母代表不同 ...

  10. 【转】The test form is only available for requests from the local machine 解决方法

    描述:在内网可以访问 WebServer     ,在外部网站无法通过IP调用 webserver 转自:http://www.cnblogs.com/xiaogelove/p/3447283.htm ...