# C. Finite or not?

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

(1n105

) — the number of queries.

Next n

lines contain queries, one per line. Each line contains three integers p, q, and b (0p1018, 1q1018, 2b1018). 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
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
/*

*/

int main(){
int T;
scanf("%d",&T);
while(T--){
ll p,q,b;
scanf("%lld %lld %lld",&p,&q,&b);
p=p%q;
ll g=gcd(p,q);

p/=g,q/=g;
if(p==0||q==1){
printf("Finite\n");
continue;
}

while(q!=1&&b!=1){
b=gcd(q,b);
q/=b;
}
if(q==1)printf("Finite\n");
else printf("Infinite\n");
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120