C. Finite or not? Codeforces Round #483 (Div. 2)

题目链接: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 }
View Code

 

转载于:https://www.cnblogs.com/lhclqslove/p/9107086.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值