码迷,mamicode.com
首页 > 其他好文 > 详细

Pseudoprime numbers POJ - 3641

时间:2018-07-22 14:12:41      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:cst   main   bitset   double   prime   prim   typedef   pen   class   

快速幂入门。。。
wa一次是因为没认识到p不能为质数

/*  
 author:hdsdogge  
 begin:  
 end:  
 cost:  
 */
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=100+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m;
ll a,p;
bool is_pirme(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return false;
    }
    return true;
}
int main() {
    //freopen("test", "r", stdin);
    //freopen("out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    while (cin >> p >> a && a + p) {
        ll ans = 1;
        ll x = a;
        ll p1 = p;
        while (p1 > 0) {
            if (p1 & 1)
                ans = (ans * x) % p;
            x = (x * x) % p;
            p1 >>= 1;
        }
        if (ans == a && !is_pirme(p)) {
            cout << "yes" << endl;
        }
        else
            cout << "no" << endl;

    }
    return 0;

}

Pseudoprime numbers POJ - 3641

标签:cst   main   bitset   double   prime   prim   typedef   pen   class   

原文地址:https://www.cnblogs.com/hdsdogge/p/9349743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!