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

C. Finite or not

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.

Examples
input

Copy
2
6 12 10
4 3 10
output

Copy
Finite
Infinite
input

Copy
4
1 1 2
9 36 2
4 12 3
3 5 4
output

Copy
Finite
Finite
Finite
Infinite
Note

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)的更多相关文章

  1. 【cf 483 div2 -C】Finite or not?(数论)

    链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...

  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#603 Div2

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

  4. CF R631 div2 1330 E Drazil Likes Heap

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

  5. CF#581 (div2)题解

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

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

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

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

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

  8. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  9. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 《java入门第一季》之面向对象(修饰符的概念和总结)

    还是由于eclipde等ide的强大功能,会自动提示你修饰符是否可行.所以对修饰符的作用了解即可: 修饰符:         权限修饰符:private,默认的,protected,public    ...

  2. How Many Processes Should Be Set For The Receiving Transaction Manager (RTM)

    In this Document   Goal   Solution   References APPLIES TO: Oracle Inventory Management - Version 10 ...

  3. [转]高级SQL注入:混淆和绕过

    ############# [0×00] – 简介[0×01] – 过滤规避(Mysql)[0x01a] – 绕过函数和关键词的过滤[0x01b] – 绕过正则表达式过滤[0×02] – 常见绕过技术 ...

  4. 带三方登录(qq,微信,微博)

    实现QQ.微信.新浪微博和百度第三方登录(Android Studio) 前言:  对于大多数的APP都有第三方登录这个功能,自己也做过几次,最近又有一个新项目用到了第三方登录,所以特意总结了一下关于 ...

  5. hibernate链接数据库链接池c3p0配置

    [html] view plain copy <bean id="dataSourceLocal" name="dataSource" class=&qu ...

  6. unity xml序列化与反序列化 多平台

    换平台确实是一个头疼的问题,本来在pc用.net的json处理数据很是顺手的,但是发布web版本后,发现他不支持.后面找了好几个开源json都不能很好的支持web,或者不能支持List等.于是我就想着 ...

  7. web报表工具FineReport的JS编辑框和URL地址栏语法简介

    JS编辑框: 1.FineReport的js. 作为一款BS产品,browser端的JavaScript是必不可少的. FineReport中的js是已经调用了finereport.js的. 大家知道 ...

  8. Spring 学习笔记 Bean的作用域

    在配置文件中定义Bean时,用户不但可以配置Bean的属性值以及相互之间的依赖关系,还可以定义Bean的作用域.作用域将对Bean的生命周期和创建方式产生影响.在低版本的Spring中,仅有两个作用域 ...

  9. javascript语言扩展:可迭代对象(5)

    文章1-4篇说的都是js中的可迭代对象,下面让我们看看ruby中的等价物. 不可否认,ruby中对于迭代器和生成器的语法都相当简洁:ruby从一开始就有一个简洁的基因,而js后来的不断扩充使得其有些语 ...

  10. Shiro之身份认证、与spring集成(入门级)

    目录 1. Shro的概念 2. Shiro的简单身份认证实现 3. Shiro与spring对身份认证的实现 前言: Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在 JavaSE 环境 ...