一个十进制分数 \(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. <Android 基础(四)> RecyclerView

    介绍 RecyclerView是ListView的豪华增强版.它主要包含以下几处新的特性,如ViewHolder,ItemDecorator,LayoutManager,SmothScroller以及 ...

  2. windows无法连接到打印机 操作失败,错误为0x00000002 解决方案

    平时使用局域网打印机没有问题,今天突然脱机了,错误号为0x00000002 服务器上打印机一切正常,别人使用也一切正常. 最后,重启了Spooler服务后搞定. 重新链接打印机,搞定!

  3. EasyUI整理学习

    参考博客: https://www.cnblogs.com/adc8868/p/6647680.html http://www.jeasyui.com/documentation/# http://w ...

  4. C# sftp通过秘钥上传下载

    一.适用场景 我们平时习惯了使用ftp来上传下载文件,尤其是很多Linux环境下,我们一般都会通过第三方的SSH工具连接到Linux,但是当我们需要传输文件到Linux服务器当中,很多人习惯用ftp来 ...

  5. Kyligence Analytics Platform Enterprise

    平台: arm 类型: ARM 模板 软件包: kap 2.3 kyanalyzer 2.3 apache kylin basic software bi big data cube data war ...

  6. Riverbed SteelHead 9.5.0

    平台: scientific linux release 6.5 类型: 虚拟机镜像 软件包: riverbed steelhead 9.5.0 basic software Enterprise i ...

  7. signal函数:void (*signal(int,void(*)(int)))(int);

    http://blog.chinaunix.net/uid-20178794-id-1972862.html signal函数:void (*signal(int,void(*)(int)))(int ...

  8. 使用VSCode搭建TypeScript开发环境 (重点)

    下载TypeScript 在CMD(Windows系统)或者终端(macOS系统)中输入一下命令: npm install -g typescript 下载VSCode VSCode是我使用过最棒的编 ...

  9. CUDA实现数组倒序

    数组倒序,将在主机上初始化的数组传输到设备上,然后用CUDA并行倒序,此时在全局内存上操作,再将结果返回到主机并验证. #include <stdio.h> #include <as ...

  10. Web/Java Web项目如何模块化?没有正文,别点

    事情是这样的,两三年前做了几个Java Web项目,由于薪资原因,原主程都离开了. 由于公司不规范,也没有留下正规的开发文档,只有一个源程序在手里.后面的很多系统维护都很被动. 领导就觉得说,这样不好 ...