Pseudoprime numbers POJ - 3641

Posted hdsdogge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pseudoprime numbers POJ - 3641相关的知识,希望对你有一定的参考价值。

快速幂入门。。。
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的主要内容,如果未能解决你的问题,请参考以下文章

Pseudoprime numbers POJ - 3641

POJ 3641 Pseudoprime numbers(快速幂)

POJ-3641 Pseudoprime numbers---快速幂

POJ 3641 Pseudoprime numbers (快速幂)

Pseudoprime numbers POJ 3641(快速幂)

POJ3641 Pseudoprime numbers (幂取模板子)