zoukankan      html  css  js  c++  java
  • 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
    ", cas, flag == 1 ? "YES" : "NO");
        }
        return 0;
    }
                
    

      

  • 相关阅读:
    IOS 沙盒机制 浅析
    IOS CALayer(二)
    IOS CALayer(一)
    IOS 二维码扫描
    IOS 二维码生成
    UIView属性
    JSON 与 XML 的比较
    Xcode 中 pch 文件配置
    Error:linker command failed with exit code 1 (use -v to see invocation)
    开发常用宏
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4757487.html
Copyright © 2011-2022 走看看