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. Ngix配置,让所有请求指向同一个文件

    统一入口使所有请求在同一个文件先验证处理,Ngix添加如下代码: location / { try_files '' /index.php; }

  2. Kotlin怎样使用Android的Dagger2

    作者:Antonio Leiva 时间:Apr 11, 2017 原文链接:https://antonioleiva.com/dagger-android-kotlin/ 在Android上,创建去耦 ...

  3. virtualBox 安装 CentOs 6.8 以及网络配置

    安装 virtual box 基本设置: 1.创建虚拟电脑 类型:Linux 版本:Red Hat(64-bit) 这个64/32 和电脑具体配置关系. 然后就是路next or 设置常规的东西. 2 ...

  4. 剑指offer-链表中倒数第K个结点14

    题目描述 输入一个链表,输出该链表中倒数第k个结点. class Solution: def FindKthToTail(self, head, k): # write code here res=[ ...

  5. MyBatis实例教程--开发环境搭建

    MyBatis实例教程--开发环境搭建 准备工作: 1.mybatis 的开发环境搭建,选择: eclipse j2ee 版本,mysql 5.1 ,jdk 1.7,mybatis3.2.0.jar包 ...

  6. this.getClass().getResource()示例详解

    public class ResourceTest extends TimerTask{ @Override    public void run() {        System.out.prin ...

  7. 简明Python3教程 1.介绍

    Python是少有的几种既强大又简单的编程语言.你将惊喜地发现通过使用Python即可轻松专注于解决问题而非和你所用的语言格式与结构. 下面是Python的官方介绍: Python is an eas ...

  8. oracle带条件的Insert语句

    背景 在一条记录完结时,自动向表中加入一条新的记录,采用的是事务处理,修改现有记录,并新增一条记录,直接采用的insert语句会报错 //主键冲突 unique constraint (XXXXXX) ...

  9. Nova Cell

    Nova Cell V2 详解 现在 ,OpenStack 在控制平面上的性能瓶颈主要在 Message Queue 和 Database . 尤其是 Message Queue , 随着计算节点的增 ...

  10. IntelliJ IDEA 创建maven项目

    说明 创建Maven项目的方式:手工创建 好处:参考IntelliJ IDEA 14 创建maven项目二(此文章描述了用此方式创建Maven项目的好处)及idea14使用maven创建web工程(此 ...