poj 3641

根据题目的定义来做,考quick_mod的应用,比较水

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <stack>
 5 #include <queue>
 6 #include <map>
 7 #include <algorithm>
 8 #include <vector>
 9 #include <cmath>
10 
11 using namespace std;
12 
13 const int maxn = 1000005;
14 
15 typedef long long LL;
16 
17 vector<int>G[maxn];
18 
19 bool prim(LL n)
20 {
21     int  t = (int)sqrt(n)+1;
22     if( n == 2 || n == 1) return 1;
23     LL i;
24     for(i=2;i<=t;i++){
25         if(n%i == 0){
26             return 0;
27             break;
28         }
29     }
30     return 1;
31 }
32 
33 LL quick_mod(LL a,LL b,LL m)
34 {
35     LL ans = 1;
36     while(b){
37         if(b&1){
38             ans = (ans*a)%m;
39         }
40         b>>=1;
41         a = a*a%m;
42     }
43     return ans;
44 }
45 
46 int main()
47 {
48     LL a,n,p,b;
49     while(cin>>p>>a&&(a+p)){
50         if(prim(p)) puts("no");
51         else{
52             LL ans = 1;
53             ans = quick_mod(a,p,p);
54             if(ans == a) puts("yes");
55             else puts("no");
56         }
57     }
58 
59 
60     return 0;
61 }
View Code

 

转载于:https://www.cnblogs.com/lmlyzxiao/p/4937283.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值