zoukankan      html  css  js  c++  java
  • POJ3641 Pseudoprime numbers(快速幂+素数判断)

    POJ3641 Pseudoprime numbers

      p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂.

      此题是大白P122 Carmichael Number 的简化版

      

    /*
    * Created:     2016年03月30日 22时32分15秒 星期三
    * Author:      Akrusher
    *
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <set>
    #include <map>
    #include <stack>
    #include <queue>
    #include <numeric>
    #include <iomanip>
    #include <bitset>
    #include <sstream>
    #include <fstream>
    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define in(n) scanf("%d",&(n))
    #define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
    #define inll(n) scanf("%I64d",&(n))
    #define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
    #define inlld(n) scanf("%lld",&(n))
    #define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
    #define inf(n) scanf("%f",&(n))
    #define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
    #define inlf(n) scanf("%lf",&(n))
    #define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
    #define inc(str) scanf("%c",&(str))
    #define ins(str) scanf("%s",(str))
    #define out(x) printf("%d
    ",(x))
    #define out2(x1,x2) printf("%d %d
    ",(x1),(x2))
    #define outf(x) printf("%f
    ",(x))
    #define outlf(x) printf("%lf
    ",(x))
    #define outlf2(x1,x2) printf("%lf %lf
    ",(x1),(x2));
    #define outll(x) printf("%I64d
    ",(x))
    #define outlld(x) printf("%lld
    ",(x))
    #define outc(str) printf("%c
    ",(str))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define SZ(x) ((int)(x).size())
    #define mem(X,Y) memset(X,Y,sizeof(X));
    typedef vector<int> vec;
    typedef long long ll;
    typedef pair<int,int> P;
    const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
    const int INF=0x3f3f3f3f;
    ll mod;
    ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    const bool AC=true;
    
    bool is_prime(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0) return false;
        }
        return n!=1;
    }
    int main()
    {
        ll a,p,ans;
        while(inlld2(p,a)==2){
        if(p==0&&a==0) break;
        mod=p;
        ans=powmod(a,p);
        if(!is_prime(p)&&ans==a){
            printf("yes
    ");
            }
            else{
                printf("no
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    JAVA_Collection容器
    ArrayList实现分组功能
    scrapy 安装出错 [err2] no such file or directory: 'README.rst'【已解决】
    python spyder 今天突然打不开了【已解决】
    SVN使用教程总结
    MVC框架浅析(基于PHP)
    Web性能优化方案
    野生程序员的故事
    js控制页面跳转,清缓存,强制刷新页面
    js中json处理总结之JSON.parse
  • 原文地址:https://www.cnblogs.com/akrusher/p/5339433.html
Copyright © 2011-2022 走看看