1. 程式人生 > >Pseudoprime numbers POJ - 3641

Pseudoprime numbers POJ - 3641

clas space using 1.0 open prime map dog end

快速冪入門。。。
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