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 这题是与数相关
首先你先要静下心来弄明白这几件事情:
第一:
gcd函数,这个是求最大公约数的函数。
第二:
在小数点后面将十进制转化为二进制,是对十进制*2取一个数,一直*2直到出现1;
例如:0.125(10)转化成二进制是0.001;
这题求1/q转化成其他进制,判断是否为一个有限小数。即1/q *b*b*b...是否==1或者大于一的整数。
注意:不能用cin输入会超时!
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll; ll gcd(ll a,ll b)//求a和b的最大公约数的函数
{
if(!b) return a;
return gcd(b,a%b);
} int main()
{
int n;
scanf("%d",&n);
while(n--)
{
ll p,q,b;
scanf("%I64d %I64d %I64d",&p,&q,&b);
ll g=gcd(p,q);
p=p%q;
p/=g;
q/=g;
if(q==1||p==0)
{
printf("Finite\n");
continue;
}
while(b!=1&&q!=1)
{
b=gcd(q,b);
q/=b;
}
if(q==1) printf("Finite\n");
else printf("Infinite\n");
}
return 0;
}

  


cf C. Finite or not? 数论的更多相关文章

  1. CF 984C Finite or not? (数论)

    CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...

  2. CF 980D Perfect Groups(数论)

    CF 980D Perfect Groups(数论) 一个数组a的子序列划分仅当这样是合法的:每个划分中的任意两个数乘积是完全平方数.定义a的权值为a的最小子序列划分个数.现在给出一个数组b,问权值为 ...

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

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

  4. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. CF984 C. Finite or not?【数论/GCD】

    [链接]:CF [题意]:n组样例,对于每组样例,给你三个数p q b,问你p/q在b进制下是不是一个有限小数,是的话输出Finite,否则输出Infinite. [分析]:b的过程是对q约分,那么只 ...

  6. CodeForces - 984C——Finite or not?分数整除问题(数论,gcd)

    题目传送门 题目描述:给你一个p/q,让你求在b进制下,这个小数是不是有限小数. 思路: 先来膜拜一个大神的博客,如何求小数的二进制表达,(感谢博主肘子zhouzi).然后小数的其他进制表达也一样. ...

  7. 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?

    题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...

  8. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  9. cf(#div1 B. Dreamoon and Sets)(数论)

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. Tomcat8源码笔记(一)Lifecycle接口

    第一次阅读Tomcat8源码,就以Lifecycle作为笔记阅读的开篇吧,一千个读者就有一千个哈姆雷特,每个人都Tomcat的理解都不同,如果不记录一次Tomcat源码可能忘了就忘了. 断断DEBUG ...

  2. Spring @Pathvariable

    先记录下@PathVariable的用法吧: @RequestMapping("/demo/{id}") @ResponseBody public User getUser(@Pa ...

  3. MySQL多表查询练习题

    一.准备数据 #创建表及插入记录 CREATE TABLE class ( cid ) NOT NULL AUTO_INCREMENT, caption ) NOT NULL, PRIMARY KEY ...

  4. 如何获得刚刚插入数据的id

    create table tblInsert ( id ,) primary key, name ) ); insert into tblInsert(name) values('张三'); sele ...

  5. 探秘小程序(7):view组件

    小程序中最基础,最常用的组件--view,类似于html中div的存在有四个属性: ①hover-class:指定按下去的样式类.当 hover-class="none" 时,没有 ...

  6. 学Java的18天,今天老师讲构造方法;

    上一篇讲到方法的调用和简单的构造方法,今天继续加深,加参数或者该参数: package sklx; public class Car{ //设三个属性 private String 品牌; priva ...

  7. 【操作系统】二、JVM线程与Linux内核线程的映射

    Linux从内核2.6开始使用NPTL (Native POSIX Thread Library)支持,但这时线程本质上还轻量级进程. Java里的线程是由JVM来管理的,它如何对应到操作系统的线程是 ...

  8. C# 特性学习笔记

    1.自己定义的特性 注意注释!!!!! 2.使用特性 3.特性的用处

  9. npm install权限问题,报错:permission denied。

    1.部署gulp项目时,nodeJs和gulp都已经正确安装,在项目内部执行npm install命令时,有些gulp的插件一直下载不成功,报错几种以下错误: “gulp-imagemin: Coul ...

  10. JavaScript 字符串转json格式

    第一种:浏览器支持的转换方式(Firefox,chrome,opera,safari,ie)等浏览器: JSON.parse(jsonstr); //可以将json字符串转换成json对象 JSON. ...