2012 #3 Arcane Numbers

Arcane Numbers 1

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 4320

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

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 long long gcd(long long a,long long b)
 7 {
 8     if(a<b)
 9         return gcd(b,a);
10     else if(b==0)
11         return a;
12     else
13         return gcd(b,a%b);
14 }
15
16 int main()
17 {
18     int T,ca=1;
19     long long A,B;
20     int i,j,k,flg;
21     scanf("%d",&T);
22     while(T--)
23     {
24         scanf("%I64d %I64d",&A,&B);
25         long long C=gcd(A,B),D;
26         A=A/C,B=B/C;
27         flg=1;
28         if(B>1)
29         {
30             while(1)
31             {
32                 if(B==1)
33                     break;
34                 D=gcd(B,C);
35                 if(D==1)
36                 {
37                     flg=0;
38                     break;
39                 }
40                 B=B/D;
41             }
42         }
43         if(A>1)
44         {
45             while(1)
46             {
47                 if(A==1)
48                     break;
49                 D=gcd(A,C);
50                 if(D==1)
51                 {
52                     flg=0;
53                     break;
54                 }
55                 A=A/D;
56             }
57         }
58         if(flg==1)
59             printf("Case #%d: YES\n",ca);
60         else
61             printf("Case #%d: NO\n",ca);
62         ca++;
63     }
64     return 0;
65 }

时间: 2024-10-13 07:46:20

2012 #3 Arcane Numbers的相关文章

数论(GCD) HDOJ 4320 Arcane Numbers 1

题目传送门 题意:有一个A进制的有限小数,问能否转换成B进制的有限小数 分析:0.123在A进制下表示成:1/A + 2/(A^2) + 3 / (A^3),转换成B进制就是不断的乘B直到为0,即(1/A + 2/(A^2) + 3 / (A^3)) * (B^m).那么(B^m) 一定要能整除(A^n),转换一下就是A的质因子B都有,可以用GCD高效计算 收获:数论题做不来可以找找规律,想想会用什么知识求解 代码: /**************************************

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

题目:传送门. 题意:将一个A进制下的有限小数转化为B进制看是否仍为有限小数. 题解:一个A进制的小数可以下次 左移动n位变成A进制整数然后再将其转化为B进制即可 即B^m/A^n要整除,因此A的质因子B必须得全部含有. #include <iostream> #include <math.h> #include <string.h> #include <algorithm> #include <stdio.h> #include <std

HDU 4321 Arcane Numbers 2

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4321 ------------------------------------------------------------------------------- 虽然有更优美的做法 不过数据范围还是可以数位$DP$的 即把模型转化为 在区间内 $mod\ a  = b\ mod\ a$ 的数所含$1$的个数之和 四维的数组分别记录 枚举到第$x$位 是否达到上限 $mod\ a$ 的余数 当前

HDU4320——GCD——Arcane Numbers 1

http://acm.hdu.edu.cn/showproblem.php?pid=4320 /* 公式:两个进制能相互转化,那么这两个进制的最小因数相同 */ /************************************************ * Author :Powatr * Created Time :2015-8-25 14:49:53 * File Name :A.cpp ************************************************

2012多校3.A(用O(log(n))判断b^k % a == 0)

Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4320 Description Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers". The ga

[SinGuLaRiTy] COCI 2011~2012 #2

[SinGuLaRiTy-1007] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s  |  Memory:256 MB 第一题:考试得分(score)[najboljih] [题目描述] 某单位举办了一次考试,考试有8道题,每道题的得分不一样.选手可以随便做,但最后只统计5道题的得分.现在给出选手每道题的得分,求出他最后的得分最大是多少? [输入] 8行,每行一个正整数X(0<=X<

URAL - 1785,1293,1877,1409,1820,1787,1264,2012

开始水URAL,今天先来几个.. 1785. Lost in Localization Time limit: 1.0 second Memory limit: 64 MB The Lavin Interactive Company, which has developed the turn-based strategy Losers-V, is constantly extending its target market by localizing the game to as many la

九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way fro

Add Two Numbers leetcode java

题目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (4 -> 6 -&