标签:src gif using contest play init code sed ons
题目链接:C. Finite or not?
题意:问一p/q能在b进制下 有限表示吗?
题解:一个分数能在b进制下有限表示必须分母的质因子也是b的质因子。例如一个分数在10进制下有限小数表示的话分母质因子只有2,5;
1 #include<bits/stdc++.h> 2 #define ll long long 3 #define ull unsigned long long 4 using namespace std; 5 const int maxn=1e2+10; 6 const int mod=1e3+5; 7 ull p,q,n,b; 8 bool judge(ull x,ull y) 9 { 10 ull tmp=y; 11 while(y<=x) 12 { 13 if(y==x)return true; 14 y*=tmp; 15 } 16 return false; 17 } 18 int main() 19 { 20 ios::sync_with_stdio(false); 21 cin.tie(0);cout.tie(0); 22 cin>>n; 23 while(n--) 24 { 25 cin>>p>>q>>b; 26 ll tmp=__gcd(p,q); 27 q/=tmp;p/=tmp; 28 p%=q; 29 if(q==1) 30 { 31 //printf("\n"); 32 cout<<"Finite"<<endl; 33 } 34 else 35 { 36 ll tt; 37 while((tt=__gcd(q,b))>1) 38 { 39 while(q%tt==0)q/=tt; 40 } 41 if(q==1) 42 { 43 //printf("Finite\n"); 44 cout<<"Finite"<<endl; 45 } 46 else 47 { 48 cout<<"Infinite"<<endl; 49 // printf("Infinite\n"); 50 } 51 } 52 } 53 return 0; 54 }
C. Finite or not? Codeforces Round #483 (Div. 2)
标签:src gif using contest play init code sed ons
原文地址:https://www.cnblogs.com/lhclqslove/p/9107086.html