zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    023 AQS--JUC的核心
    022 Future接口
    021 Callable接口
    020 线程的综合考虑
    019 线程协作
    命令,lldb,llvm,gdb,gcc,
    @class,import,
    arc,自动引用计数,
    写在哪里,
    40岁生日,
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4937283.html
Copyright © 2011-2022 走看看