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 p

, q and b. You need to answer whether the result of p/q in notation with base b

is a finite fraction.

A fraction in notation with base b

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 n

(1≤n≤105) — the number of queries.

Next nlines contain queries, one per line. Each line contains three integers p, q, and b (0≤p≤1018, 1≤q≤1018, 2≤b≤1018).

All numbers are given in notation with base 10

.

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,510

43=1,(3)10

936=14=0,012

412=13=0,13

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
//codeforces
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    long long p,q,b,temp;
    cin>>n;
    while(n--){
    cin>>p>>q>>b;
    temp=__gcd(p,q);
    p/=temp;q/=temp;
    int flag=1;
    while(1){
            if(q==1){
            break;
        }
        temp=__gcd(q,b);
        if(temp==1){
            cout<<"Infinite"<<endl;
            flag=0;break;
        }
        while(q%temp==0){
            q/=temp;
        }
    }
    if(flag) cout<<"Finite"<<endl;
    }
    return 0;
}

Codeforces Round #483 (Div. 2)C题的更多相关文章

  1. Codeforces Round #483 (Div. 2) B题

    B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  3. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  4. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  5. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  6. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  8. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  9. Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

    题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...

随机推荐

  1. 主动驱动事件执行--createEvent

    1. createEvent(eventType)参数:eventType 共5种类型:    Events :包括所有的事件.           HTMLEvents:包括 'abort', 'b ...

  2. Java 反射、注解

    1. 泛型 基本用法.泛型擦除.泛型类/泛型方法/泛型接口.泛型关键字.反射泛型! a. 概述 泛型是JDK1.5以后才有的, 可以在编译时期进行类型检查,且可以避免频繁类型转化! // 运行时期异常 ...

  3. CentOS新增硬盘,重新扫描总线

    Centos 新增硬盘以后,系统不能自动进行识别. 1. 由于不知道新增硬盘挂载的位置,可以先查看现有硬盘挂载的适配器. [root@localhost ~]# ls -l /sys/block/sd ...

  4. C语言实现整数数组的逆置算法

    读入100个整数到一个数组中,写出实现该数组进行逆置的算法. 方法一: 假设100个整数读入到数组a中,算法f1的思想是分别从数组两端依次将对应数进行交换,即a[i]与a[100 - i - 1]进行 ...

  5. 定期重启SSRS 服务

    SSRS 在执行了一段时间之后会变得非常卡,遇到好几次内存暴涨,CPU100%的情况. 但是在查询了一通以后发现,这个时间没有人在运行报告,不知道是哪里有问题,没有回收... 所以决定定期在晚上没有不 ...

  6. Javascript之全局变量和局部变量部分讲解

    以此文作为自己学习的一个总结. 关于全局变量和局部变量的一句简单的定义:在函数外声明的变量都为全局变量,在函数内声明的为局部变量. 一.局部变量和全局变量重名会覆盖全局变量 var a = 1; fu ...

  7. git 命令备忘

    git 常用命令备忘 仅作为日常使用备忘,并非常用命名整理 删除源端分支 git push orgin --delete branch_a a分支某次提交应用到b分支 切换到branch_b 分支: ...

  8. IIS 无法安装URL重写模块的解决办法 UrlReWrite (.NET`SQL技术交流 群号206656202)

    下载和安装URL Rewrite IIS8默认是没有安装URL重写工具的,必须要自己下载安装. 如果IIS上默认有安装Web平台安装程序,我们可以使用平台自动安装URL Rewrite重写工具,打开I ...

  9. 【转】Java中的多线程你只要看这一篇就够了

    https://www.jianshu.com/p/40d4c7aebd66 引 如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只有一个目的, ...

  10. February 11 2017 Week 6 Saturday

    Love means never having to say you're sorry. 爱就是永远不必说对不起. Yesterday I heard an interesting story fro ...