链接:http://codeforces.com/contest/984/problem/C

题意

三个数p, q, b, 求p/q在b进制下小数点后是否是有限位。

思路

题意转化为是否q|p*b^x,即看b和q有没有相同的质因子。如果用筛选质因子的话1e18的数会超时,所以每次求出b和q的gcd,再让q/gcd,如果q最后是1那么b和q拥有相同质因子,输出Finite,反之Infinite。

附代码:

#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
LL gcd(LL a, LL b)
{
if(b == ) return a;
return gcd(b, a%b);
}
int main()
{
LL p, q, b, t;
cin>>t;
while(t--)
{
scanf("%lld%lld%lld", &p, &q, &b);
q = q/gcd(p, q);
LL a;
while(q!=)
{
a = gcd(b, q);
if(a == ) break;
while(q%a==)
{
q /= a;
}
}
if(q!=) puts("Infinite");
else puts("Finite");
}
return ;
}

【cf 483 div2 -C】Finite or not?(数论)的更多相关文章

  1. CF#483(div2 C)

    http://codeforces.com/contest/984/problem/C C. Finite or not time limit per test 1 second memory lim ...

  2. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  3. cf C. Finite or not? 数论

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

  4. 「CF#554 div2」题解

    A 水题一道. 题目的大致意思就是:给你两个集合,求集合间有多少数对和是奇数. 题解,开\(4\)个桶后,求一个\(min\)就可以了. #include <bits/stdc++.h> ...

  5. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  6. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  7. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  8. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  9. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

随机推荐

  1. 19. Remove Nth Node From End of List(移除倒数第N的结点, 快慢指针)

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  2. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...

  3. Python+Appium API

    1.contextscontexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控 ...

  4. 【android】通过leakCanary找出程序内存泄露点

    背景 内存泄露是咱新手比较头痛的问题,因为它不像崩溃,在开发环境可以根据提示的错误信息排查问题. 你都不知道咱的app是否哪个犄角旮旯藏着一个吞噬内存的黑洞. 排查android 内存泄露比较底层高端 ...

  5. css 中 transition 需要注意的问题

    cubic-bezier 是 transition-timing-function 的值的一种. 四个参数的关系式如下(t 代表时间,取值范围 [0, 1]):P0(1-t)3 + 3P1t(1-t) ...

  6. Redis学习笔记之Redis中5种数据结构的使用场景介绍

    原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 redis 中一共有5种数据结构 ...

  7. 开发人员不可不看的 OBD通讯协议知识

    OBD-II Network Standards» J1850 VPW– Adopted by GM; also known as Class 2.– Adopted by Chrysler (kno ...

  8. Juniper SRX防火墙简明配置手册(转)

    在执行mit命令前可通过配置模式下show命令查看当前候选配置(Candidate Config),在执行mit后配置模式下可通过run show config命令查看当前有效配置(Active co ...

  9. maven中pom.xml解释

    知识点:解释maven中,各个标签的含义 转载:http://blog.sina.com.cn/s/blog_534f69a001010lpv.html (1)Introduce maven项目的核心 ...

  10. 2017 ACM/ICPC 南宁区 网络赛 Overlapping Rectangles

    2017-09-24 20:11:21 writer:pprp 找到的大神的代码,直接过了 采用了扫描线+线段树的算法,先码了,作为模板也不错啊 题目链接:https://nanti.jisuanke ...