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. spring AOP 之二:@AspectJ注解的3种配置

    @AspectJ相关文章 <spring AOP 之二:@AspectJ注解的3种配置> <spring AOP 之三:使用@AspectJ定义切入点> <spring ...

  2. MyBatis——MyEclipse中使用mybatis-generator

    mybatis-generator可以根据数据库的表来生成POJO类.mapper.xml和DAO接口,用这个插件会大大地提高开发的效率.网上虽然有一些使用这个插件的教程,但我单个试了并不能成功,会出 ...

  3. windows server 证书的颁发与IIS证书的使用

    最近工作业务要是用服务器证书验证,在这里记录下一. 1.添加服务器角色 [证书服务] 2.一路下一步直到证书服务安装完成; 3.选择圈选中的服务器证书 4.点击[创建证书申请] 5.填写信息 6.下一 ...

  4. activeX

    对外接口和classid在idl文件中,接口功能实现在ctrl类中实现

  5. [PHP]算法- 判断是否为二叉搜索树的后序遍历序列的PHP实现

    二叉搜索树的后序遍历序列: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 思路: 1.后序遍历是 左右中 ...

  6. Spring全家桶系列–SpringBoot之入门JPA

    //本文作者:cuifuan 什么是JPA? 一种规范,并非ORM框架,也就是ORM上统一的规范 用了之后可以做什么,为什么要用? 代码解释: 实体类 package com.example.spri ...

  7. Android ContentProvider数据共享

    一.构造一个自己的Provider实现App之间数据共享 1.我们先来了解一下   Uri(统一资源定位符) 定义:每一个Content Provider使用一个公开的URI唯一标示其数据集,Andr ...

  8. vue中使用axios(异步请求)和mock.js 模拟虚假数据

    一.使用axios 1.安装 npm install --save axios 2.引用 import Axios from 'axios' Vue.prototype.Axios = Axios 二 ...

  9. 洛谷P4563 [JXOI2018]守卫(dp)

    题意 题目链接 Sol 非常有意思的题目. 我们设\(f[l][r]\)表示区间\([l,r]\)的答案. 显然\(r\)位置一定有一个保镖 同时不难观察到一个性质:拿\([1, n]\)来说,设其观 ...

  10. python之数据类型

    1.整数(int)integer 直接写出数字就是整数例: a = 0#查看变量的数据类型 type() -> #<class 'int'> class类,类型,类别print(10 ...