首页 > 其他 > 详细

Pseudoprime numbers(POJ 3641 快速幂)

时间:2016-02-15 16:07:30      阅读:230      评论:0      收藏:0      [点我收藏+]
 1 #include <cstring>
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 #define LL long long
 8 LL p,res,a;
 9 bool judge_prime(LL k)
10 {
11     LL i;
12     LL u=int(sqrt(k*1.0));
13     for(i=2;i<=u;i++)
14     {
15         if(k%i==0)
16             return 0;
17     }
18     return 1;
19 }
20 int main()
21 {
22     freopen("in.txt","r",stdin);
23     while(scanf("%lld%lld",&p,&a))
24     {
25         if(p==0&&a==0)
26             break;
27         if(judge_prime(p))
28         {
29             printf("no\n");
30             continue;
31         }
32         res=1;
33         LL t=p;
34         LL w=a;
35         while(p)
36         {
37             if(p&1) res=(res*a)%t;
38             a=(a*a)%t;
39             p>>=1;
40         }
41         if(res==w)
42             printf("yes\n");
43         else
44             printf("no\n");
45     }
46 }

 

Pseudoprime numbers(POJ 3641 快速幂)

原文:http://www.cnblogs.com/a1225234/p/5190495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!