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. js数字格式化千分位格式

    带小数点的 var a = 8462948.2453; console.log(a.toLocaleString()) //8,462,948.245 不带小数点的 num.toString().re ...

  2. Selenide 简单实现自动化测试

    Selenide 网址:http://selenide.org/ github 地址:https://github.com/codeborne/selenide Selenide 早些年一直使用,中间 ...

  3. LeetCode 82 ——删除排序链表中的重复元素 II

    1. 题目 2. 解答 新建一个链表,并添加一个哨兵结点,从前向后开始遍历链表. 如果下一个结点的值和当前结点的值相等,则循环向后遍历直到找到一个和当前结点值不相等的结点: 反之,如果下一个结点的值和 ...

  4. Spark实战练习03--Pair RDD

    一.场景 现有某网站的网站日志,内容为用户对网站的请求,包含user ID.IP address.datetime……等等 另有一份文件中包含用户的账户详细信息数据,包含User ID.creatio ...

  5. POJ 3860 Fruit Weights(数学+最长路径 or 最短路径)

    Description Have you ever thought about comparing the weight of fruits? That’s what you should do in ...

  6. [持续补充]开发过程中常见bug查找思路

    文件夹下载不下来或者无法访问,很多时候是因为没有该文件夹的权限,或者没有将该文件夹挂载到对应docker下. 远程服务器和本地服务器测试结果不同,需要排查代码是否是git上同一版本的代码. 代码相同, ...

  7. [转]Linux UDP严重丢包问题的解决

    测试系统在Linux上的性能发现丢包率极为严重,发210000条数据,丢包达110000之巨,丢包率超过50%.同等情形下Windows上测试,仅丢几条数据.形势严峻,必须解决.考虑可能是因为协议栈B ...

  8. kudu介绍及安装配置

    kudu介绍及安装配置 介绍 Kudu 是一个针对 Apache Hadoop 平台而开发的列式存储管理器.Kudu 共享 Hadoop 生态系统应用的常见技术特性: 它在 commodity har ...

  9. 2018-2-6考试(COCI2014/2015 Contest#5)

    T1:FUNGHI(1s,32M,50pts)得分:50 题意:给你8个数组成一个环,要你求出其中连续的4个数,让它们的和最大 题解:暴力求出每一连续4个数之和,比较一下就好 标签:模拟 C++ Co ...

  10. js金额转大写数字

    //金额转大写数字 const intToChinese = money => { //汉字的数字 let cnNums = new Array('零', '壹', '贰', '叁', '肆', ...