一个十进制分数 \(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?的更多相关文章

  1. Finite State Machine 是什么?

    状态机(Finite State Machine):状态机由状态寄存器和组合逻辑电路构成,能够根据控制信号按照预先设定的状态进行状态转移,是协调相关信号动       作.完成特定操作的控制中心. 类 ...

  2. Finite State Machine

    Contents [hide]  1 Description 2 Components 3 C# - FSMSystem.cs 4 Example Description This is a Dete ...

  3. pumping lemma for finite regular language?

    some books describe pumping lemma as this: Let L be a regular language. Then there exists an integer ...

  4. codeforces 983A Finite or not?

    题意: 判断一个分数在某一进制下是否为无限小数. 思路: 首先把这个分数约分,然后便是判断. 首先,一个分数是否为无限小数,与分子是无关的,只与分母有关. 然后,再来看看10进制的分数,可化为有限小数 ...

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

    C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  6. CF983A Finite or not?(数学)

    题意:给出分母,分子和进制,要求判断该数是否为有限小数. Solution 表示并不知道怎么判断. 度娘:“一个分数在最简分数的情况下,如果它的分母只含有2和5两个质因数,这个分数就能化成有限小数.” ...

  7. cf C. Finite or not? 数论

    You are given several queries. Each query consists of three integers pp, qq and bb. You need to answ ...

  8. 解题:CF983A Finite or not

    题面 一个$b$进制最简分数是有限循环小数当且仅当其分母没有与$b$不同的质因子,小学数奥内容水过 #include<cstdio> #include<cstring> #in ...

  9. 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?

    题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...

随机推荐

  1. 独立安装Oracle Hyperion Enterprise Performance Management 验证过程

    在安装EPM的过程中,都是安装既定的操作手册进行,只是一个过程的重复,对自己安装不会留下深刻的印象.根据自己学习体会,制定安装步骤,去验证自己学习过程中的体会,加深学习印象,解决安装中遇到的问题,模仿 ...

  2. Invoke 和 BeginInvoke 的区别(转发)

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...

  3. linux 下源码编译环境配置

    yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel \ fontconfig fo ...

  4. 集成Ehcache

    提醒 这一小节的是如何在应用层(service或者module或action类)中使用ehcache   准备工作 下载ehcache 你需要一个js文件   请务必阅读下面代码中的注释!! 分情况选 ...

  5. python request下载文件时,显示进度以及网速

    import requests import time def downloadFile(name, url): headers = {'Proxy-Connection':'keep-alive'} ...

  6. 用virtualenv构建一个新的python环境,这个新的环境在这个创建的文件夹下

    http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143271210830032 ...

  7. GPU && CUDA:主机和设备间数据传输测试

    数据传输测试,先从主机传输到设备,再在设备内传输,再从设备传输到主机. H-->D D-->D D-->H // moveArrays.cu // // demonstrates C ...

  8. sass安装更新及卸载方法

    在 Windows 平台下安装 Ruby 需要先有 Ruby 安装包,大家可以到 Ruby 的官网(http://rubyinstaller.org/downloads)下载对应需要的 Ruby 版本 ...

  9. Spring+ ApplicationListener

    有时候 需要在容器初始化完成后,加载些 代码字典或不常变的信息  放入缓存之类的,这里使用spring 初始化bean,并实例化 1.创建一个ApplicationListener类 import o ...

  10. (76)zabbix_agentd.conf配置文件详解

    ############ GENERAL PARAMETERS ################# ### Option: PidFile# Name of PID file.# Agent PID文 ...