zoukankan      html  css  js  c++  java
  • Codeforces Round #483 (Div. 1) A. Finite or not?

    最简分数p/q在b进制下的小数为无限小数的充要条件是

      q不完全由b的某些因子乘积构成

    #include<bits/stdc++.h>
    #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    #define re(i,l,r) for(int i=(l);i<=(r);i++)
    #define Clear(a,b) memset(a,b,sizeof(a))
    #define inout(x) printf("%d",(x))
    #define douin(x) scanf("%lf",&x)
    #define strin(x) scanf("%s",(x))
    #define op operator
    typedef unsigned long long ULL;
    typedef const int cint;
    typedef long long LL;
    using namespace std;
    template<typename Q>
    void inin(Q &x)
    {
        x=0;int f=0;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        x=f?-x:x;
    }
    LL gcd(LL a,LL b)
    {
        LL c;
        while(a%b)
        {
            c=a%b;
            a=b,b=c;
        }
        return b;
    }
    int main()
    {
    //    freopen("a.in","r",stdin);
    //    freopen("a.out","w",stdout);
        LL p,q,b,t;
        inin(t);
        while(t--)
        {
            inin(p),inin(q),inin(b);
            if(!p){cout<<"Finite\n";continue;}
            LL d=gcd(q,p);
            q/=d;
            while(q%b==0)q/=b;
            d=gcd(q,b);
            while(d>1)
            {
                while(!(q%d))
                    q/=d;
                d=gcd(b,q);
            }
            if(q==1)cout<<"Finite\n";
            else cout<<"Infinite\n";
        }
        return 0;
    }
  • 相关阅读:
    初识STM32标准库
    自己写库—构建库函数雏形
    使用寄存器点亮LED等
    新建工程---寄存器版
    什么是寄存器
    初识STM32
    ST-LINK驱动的安装
    MDK5使用技巧
    开发环境的搭建
    1行Python代码制作动态二维码
  • 原文地址:https://www.cnblogs.com/NoCEinVegetable/p/9073091.html
Copyright © 2011-2022 走看看