cf984c Finite or not?

Posted poorpool

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf984c Finite or not?相关的知识,希望对你有一定的参考价值。

一个十进制分数 \(p/q\)\(b\) 进制下是有限小数的充要条件是 \(q\) 的所有质因子都是 \(b\) 的质因子。

First, if \(p\) and \(q\) are not coprime, divide them on \(\gcd(p,q)\). Fraction is finite if and only if there is integer \(k\) such that \(q∣p?b^k\). Since \(p\) and \(q\) are being coprime now, \(q∣b^k\) \(\Rightarrow\) all prime factors of \(q\) are prime factors of \(b\).

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int n;
ll p, q, b;
ll gcd(ll a, ll b){
    return !b?a:gcd(b, a%b);
}
int main(){
    cin>>n;
    while(n--){
        scanf("%I64d %I64d %I64d", &p, &q, &b);
        ll f=gcd(p, q);
        p /= f; q /= f;
        f = gcd(q, b);
        while(f!=1){
            while(q%f==0)   q /= f;
            f = gcd(q, b);
        }
        if(b%q) printf("Infinite\n");
        else    printf("Finite\n");
    }
    return 0;
}

以上是关于cf984c Finite or not?的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 984 C. Finite or not?

C. Finite or not? Codeforces Round #483 (Div. 2)

Codeforces Round #483 (Div. 2) C.Finite or not? 关于欧几里得的应用

Codeforces Round #483 (Div. 1) A. Finite or not?

解决go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘(代码片段

解决pandas:ValueError: Cannot convert non-finite values (NA or inf) to integer