题意:给你一个分数,问你在b进制下能否化成有限小数。

条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能。

参见代码:反复从q中除去b和q的公因子部分,并缩小该公因子,继续尝试。直到q没有和b的公共因子为止,如果q变成了1,那么有限,否则无限。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int T;
ll q,p,b;
int main(){
scanf("%d",&T);
for(;T;--T){
scanf("%I64d%I64d%I64d",&p,&q,&b);
if(p==q || p==0ll || q/__gcd(p,q)==1ll){
puts("Finite");
continue;
}
q/=__gcd(p,q);
ll g=__gcd(b,q);
while(g!=1){
q/=g;
g=__gcd(g,q);
}
if(q==1ll){
puts("Finite");
}
else{
puts("Infinite");
}
}
return 0;
}

【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?的更多相关文章

  1. Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

    题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...

  2. 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid

    题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...

  3. Codeforces Round #483 (Div. 2) B题

    B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #483 (Div. 2)C题

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

  5. Codeforces Round #483 (Div. 2) B. Minesweeper

    题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...

  6. 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 ...

  7. Codeforces Round #483 (Div. 2) D. XOR-pyramid

    D. XOR-pyramid time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  8. Codeforces Round #483 (Div. 2)

    题目链接: https://cn.vjudge.net/contest/229761 A题: n个数字,两个人轮流去数字,直到剩下最后一个数字为止,第一个人希望剩下的数字最小,第二个人希望数字最大,最 ...

  9. Codeforces Round #483 Div. 1

    A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...

随机推荐

  1. hdu 5463 Clarke and minecraft

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5463 Clarke and minecraft Time Limit: 2000/1000 MS (J ...

  2. #ifdef __cplusplus extern "C" { #endif”的定义的含义

    看一些程序的时候老是有“#ifdef __cplusplusextern "C" {#endif”的定义,搞搞清楚是怎么回事: Microsoft-Specific Predefi ...

  3. centos 升级linux内核

    =============================================== 2018/1/14_第1次修改                       ccb_warlock == ...

  4. MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应解决方法

    问题: MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应 解决方法: 如果工作空间的问题,那么需要删除你工作空间的一个文件就可以解决了.这个 ...

  5. git clone命令使用

    git clone命令使用 分类: 项目构建2013-06-26 15:43 38660人阅读 评论(2) 收藏 举报 GitClone git clone 命令参数: usage: git clon ...

  6. IPv4的核心管理功能/proc/sys/net/ipv4/*

    I /proc/sys/net/ipv4/tcp_syncookies SYN Cookies模块可以在系统随机端口(1024:65535)即将用完时自动启动,用来应对Dos攻击.当启动SYN Coo ...

  7. 分析new delete 的本质

    在程序设计中,数据可能会存在不同的内存空间,如函数栈 堆   全局变量区  ,今天我们来分析一下C++中堆分配方式和C语言的堆分配方式异同,从而更好的理解new  delete本质 C语言使用mall ...

  8. Luogu P1750 【出栈序列】

    一眼(万年)贪心minn设小调不出来祭 首先要保证更靠前的输出更小那么容易想到,对于之后可能入栈的元素(即栈的剩余空间仍能装下的所有元素),我们可以取其中的最小值minn,和栈顶元素$top$比较,如 ...

  9. 阿里云宝塔Linux服务器管理面版初始化地址不能登入(原创)

    宝塔面板是一款可以让Linux服务器实现图形可视化操作的集成系统. 安装好以后,页面初始化登录地址http://{您的服务器IP}:888不能登入. 不能登入通常是我们没有权限访问,需要更改安全组赋予 ...

  10. phpmyadmin新加用户登陆不了,测试解决方案。

    今天在给项目配置数据库管理平台时遇到一个问题,不论怎么添加mysql用户在登陆phpmyadmin时始终无法登陆,不管准不准许为空依然报出#1045 无法登陆服务器的错误,最后打开mysql库中use ...