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
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

long long a, b;
long long  gcd(long long a, long long b)
{
    return b == 0 ? a : gcd(b, a%b);
}
int main()
{
    int T;
    scanf("%d", &T);
    for(int cas = 1; cas <= T; cas++){
        scanf("%I64d%I64d", &a, &b);
        long long  c = gcd(a, b);
        long long  d;
        a /= c, b /= c;
        int flag = 1;
        while(1){
            if(b == 1) break;
            d = gcd(b, c);
            if(d == 1){
                flag = 0;
                break;
            }
            b /= d;
        }
        while(1){
            if(a == 1) break;
            d = gcd(a, c);
            if(d == 1){
                flag = 0;
                break;
            }
            a /= d;
        }
        printf("Case #%d: %s\n", cas, flag == 1 ? "YES" : "NO");
    }
    return 0;
}

  

时间: 2025-01-11 00:23:05

HDU4320——GCD——Arcane Numbers 1的相关文章

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 ga

数论(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$ 的余数 当前

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

2018SDIBT_国庆个人第三场

A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of n

国庆练习3

Benches CF 1042A There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn availa

CF1245 A. Good ol&#39; Numbers Coloring(java与gcd)

题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11-06-12:07 about: */ import java.io.*; import java.util.*; public class CF1245 { public static void main(String[] args) { Scanner In=new Scanner(System.

HDU 5505 GT and numbers(GCD魔法)

题目链接:点击打开链接 题意:给两个数n和m, n每次乘以它的因子变成一个新的值, 求最少乘几次可以变成m. 思路:每次乘以的整数v有两个要求:1.它是n的因子:2.它要尽量大. 又因为如果n能最终到达m,一定是乘以n的k倍, 所以只要n能被m整除, 那么每次取gcd(n, m/n)就行了. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #i