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

 

posted @ 2015-11-04 20:34  lmlyzxiao  阅读(114)  评论(0编辑  收藏  举报