CF#483(div2 C)
http://codeforces.com/contest/984/problem/C
C. Finite or not
1 second
256 megabytes
standard input
standard output
You are given several queries. Each query consists of three integers pp, qq and bb. You need to answer whether the result of p/qp/q in notation with base bb is a finite fraction.
A fraction in notation with base bb is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of queries.
Next nn lines contain queries, one per line. Each line contains three integers pp, qq, and bb (0≤p≤10180≤p≤1018, 1≤q≤10181≤q≤1018, 2≤b≤10182≤b≤1018). All numbers are given in notation with base 1010.
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
2
6 12 10
4 3 10
Finite
Infinite
4
1 1 2
9 36 2
4 12 3
3 5 4
Finite
Finite
Finite
Infinite
612=12=0,510612=12=0,510
43=1,(3)1043=1,(3)10
936=14=0,012936=14=0,012
412=13=0,13412=13=0,13
题目标签:数论;
题目大意:判断p/q在b进制下是否为有限小数;

0.0
题目思路:不断的用b去消除q中的因子,但是求出一个g=gcd(q,b)后,必须直接将q中的所有g都除尽,否则会超时;标程是不断的寻找b=gcd(q,b),因为每次q除尽最大公约数后,q中含有的只能是原来的最大公约数中的因子,所以不用每次用b去更新q,可以每次更新完q后,也更新b值;
小数的二进制转换:乘基取整,顺序排列;
#include <iostream>
#include <cstdio>
//小数的二进制转换:乘基取整,顺序排列;
//b的k次方%q==0;
//判断k个b能否将q的所有因子均消耗完;
using namespace std;
typedef long long ll; ll gcd(ll x,ll y)
{
if(y==)return x;
return gcd(y,x%y);
}
int main()
{
int n;
ll p,q,b;
scanf("%d",&n);
while(n--)
{
bool flag=false;
scanf("%I64d%I64d%I64d",&p,&q,&b);
if(p==)q=;
q/=gcd(p,q);
ll g=gcd(q,b);
while(g!=){ //q,b互质;
while(q%g==)q/=g;
g=gcd(q,b);
}
if(q==)
printf("Finite\n");
else
printf("Infinite\n");
}
return ;
}
CF#483(div2 C)的更多相关文章
- 【cf 483 div2 -C】Finite or not?(数论)
链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...
- 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, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- CF R303 div2 C. Woodcutters
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 实例分析exec函数
fork()函数通过系统调用创建一个与原来进程(父进程)几乎完全相同的进程(子进程是父进程的副本,它将获得父进程数据空间.堆.栈等资源的副本.注意,子进程持有的是上述存储空间的"副本&quo ...
- Ubuntu15.04 + Matlab2014a + MatConvNet install and compile
MatConvNet is a MATLAB toolbox implementingConvolutional NeuralNetworks (CNNs) for computer vision a ...
- 【matlab编程】Matlab版扫雷
我发现有些人平常闲着的时候会玩window自带的游戏,其中最常见的就是扫雷和纸牌.本来想用matlab编写全自动扫雷程序用来作弊,可是后来发现扫雷问题是NP完全问题(正如:旅行商NP难问题一样不能被解 ...
- Android应用---基于NDK的samples例程hello-jni学习NDK开发
Android应用---基于NDK的samples例程hello-jni学习NDK开发 NDK下载地址:http://developer.android.com/tools/sdk/ndk/index ...
- Ext JS 5 beta版发布
原文:Announcing Public Beta of Ext JS 5 我们非常高兴的宣布,Sencha Ext JS 5 beta版本开始进行公测了.这个beta版本可以让你.我们Sencha社 ...
- 【面试笔试算法】Program 6: 字符消除(hiho题库)
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的: 1) ...
- 使用Gradle发布SNAPSHOT版本到JCenter(oss.jfrog.org)
回顾历史 发布SNAPSHOT版本的问题 解决问题 完整脚本 使用方法 本文原创. 转载请注明CSDN博客出处: http://blog.csdn.net/maosidiaoxian/article/ ...
- objc写一个NSMutableArray不连续索引替换对象的方法
NSMutableArray内置的方法-(void)replaceObjectsAtIndexes:(NSIndexSet*)set withObjects:(NSArray*)objs 只能替换一段 ...
- HBase Muti-Master
为了保证HBase集群的高可靠性,HBase支持多Backup Master 设置.当Active Master挂掉后,Backup Master可以自动接管整个HBase的集群. 该配置极其简单: ...
- rails4 中使用分页的方法
以前老版本的rails中默认自带分页方法,不过从rails2.0开始就将内置的分页pagination对象移除了,改以第三方gem提供支持.要在新的rails里使用分页也是非常简单啦,首先安装will ...