-
Notifications
You must be signed in to change notification settings - Fork 2
/
CF_483_Div2_C.cpp
65 lines (59 loc) · 999 Bytes
/
CF_483_Div2_C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
int gcd(long long int a,long long int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
int main()
{
long int t;
cin>>t;
while(t--)
{
long long int n,m,b;
cin>>n>>m>>b;
long int c=gcd(n,m);
m=m/c;
bool flag=1;
long long int j=sqrt(m);
if(m%2==0)
{
if(2>b||b%2!=0)
{
flag=0;
// break;
}
while(m%2==0)
m=m/2;
}
for(long int i=3;i<=j;i+=2)
{
if(m%i==0)
{
if(i>b||b%i!=0)
{
flag=0;
break;
}
while(m%i==0)
{
m=m/i;
}
// cout<<m<<" "<<flag<<endl;
}
}
if(m>2)
{
if(m>b)
flag=0;
else if(b%m!=0)
flag=0;
}
if(flag)
cout<<"Finite"<<endl;
else
cout<<"Infinite"<<endl;
}
}