模板题,直接用

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define EPS 1e-8
#define DINF 1e15
#define MAXN 100050
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 1LL<<60
#define PI 3.14159265358979323846
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define BUG cout<<"BUG! "<<endl
#define ABS(a) ((a)>0?(a):(-a))
#define LINE cout<<"------------------ "<<endl
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("in.txt","w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define read(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define write(a) printf("%d\n",a)
#define write2(a,b) printf("%d %d\n",a,b)
#define write3(a,b,c) printf("%d %d %d\n",a,b,c)
#pragma comment (linker,"/STACK:102400000,102400000")
template<class T> inline T L(T a) {return (a << );}
template<class T> inline T R(T a) {return (a << | );}
template<class T> inline T lowbit(T a) {return (a & -a);}
template<class T> inline T Mid(T a,T b) {return ((a + b) >> );}
template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;}
template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;}
template<class T> inline T Min(T a,T b) {return a < b ? a : b;}
template<class T> inline T Max(T a,T b) {return a > b ? a : b;}
template<class T> inline T Min(T a,T b,T c) {return min(min(a,b),c);}
template<class T> inline T Max(T a,T b,T c) {return max(max(a,b),c);}
template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));}
template<class T> inline T mod(T x,T y) {y = ABS(y); return x >= ? x % y : x % y + y;}
template<class T> inline T mul_mod(T a,T b,T n) {
T ret = ,tmp = a % n;
while(b){
if((b&) && (ret+=tmp)>=n) ret -= n;
if((b>>=) && (tmp<<=)>=n) tmp -= n;
}return ret;
}
template<class T> inline T pow_mod(T a,T b,T n){
T ret = ; a = a % n;
while(b){
if (b&) ret = mul_mod(ret,a,n);
if (b>>=) a = mul_mod(a,a,n);
}return ret;
}
template<class T> inline T exGCD(T a, T b, T &x, T &y){
if(!b) return x = ,y = ,a;
T res = exGCD(b,a%b,x,y),tmp = x;
x = y,y = tmp - (a / b) * y;
return res;
}
template<class T> inline T reverse_bits(T x){
x = (x >> & 0x55555555) | ((x << ) & 0xaaaaaaaa); x = ((x >> ) & 0x33333333) | ((x << ) & 0xcccccccc);
x = (x >> & 0x0f0f0f0f) | ((x << ) & 0xf0f0f0f0); x = ((x >> ) & 0x00ff00ff) | ((x << ) & 0xff00ff00);
x = (x >> & 0x0000ffff) | ((x <<) & 0xffff0000); return x;
} typedef long long LL; typedef unsigned long long ULL;
//typedef __int64 LL; typedef unsigned __int64 ULL;
/********************* By F *********************/
inline bool witness(LL a,LL x){
LL m = x-,s = ;
while(!(m&)) m>>=,s++;
LL res = pow_mod(a,m,x);
if(res == || res == x-) return ;
while(s--){
res = mul_mod(res,res,x);
if(res == x-) return ;
}return ;
}
inline bool miller(LL x,int time){
if(x == || x == || x == || x == ) return ;
if(x == || !(x&) || x% == || x% == || x% == ) return ;
while(time--){
LL r = rand()%(x-) + ;
if(gcd(r,x) != || !witness(r%x,x)) {return ;}
}return ;
}
int main(){
//FIN;
LL p,a;
while(~scanf("%lld%lld",&p,&a)){
if(p == && a == ) break;
if(miller(p,)){
printf("no\n");
}else{
LL t = pow_mod(a,p,p);
if(t == a) printf("yes\n");
else printf("no\n");
}
}
return ;
}

POJ 3641 Pseudoprime numbers (miller-rabin 素数判定)的更多相关文章

  1. poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题

    Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7954 Accepted: 3305 D ...

  2. poj 3641 Pseudoprime numbers

    题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...

  3. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  4. poj 3641 Pseudoprime numbers Miller_Rabin测素裸题

    题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...

  5. poj 3641 Pseudoprime numbers(快速幂)

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  6. POJ2429_GCD &amp; LCM Inverse【Miller Rabin素数測试】【Pollar Rho整数分解】

    GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9756Accepted: 1819 ...

  7. POJ1811_Prime Test【Miller Rabin素数测试】【Pollar Rho整数分解】

    Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time ...

  8. POJ1811_Prime Test【Miller Rabin素数測试】【Pollar Rho整数分解】

    Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time ...

  9. Miller Rabin素数检测与Pollard Rho算法

    一些前置知识可以看一下我的联赛前数学知识 如何判断一个数是否为质数 方法一:试除法 扫描\(2\sim \sqrt{n}\)之间的所有整数,依次检查它们能否整除\(n\),若都不能整除,则\(n\)是 ...

随机推荐

  1. Android里使用正則表達式

    在Android里怎样使用正則表達式: 以验证username为例.username一般字母开头,同意字母数字下划线.5-16个字节: String regEx = "^[a-zA-Z][a ...

  2. 从Oracle Database 角度来看浪潮天梭K1主机的操作系统选择

    背景: 浪潮天梭k1主机.事实上分好几个类别: K1-950 intel 安腾cpu K1-930 intel 安腾cpu K1-910 intel 安腾cpu K1-800 intel 志强cpu ...

  3. sass10 demo1

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. spark 类标签的稀疏 特征向量

    一个向量(1.0,0.0,3.0)它有2中表示的方法 密集:[1.0,0.0,3.0]    其和一般的数组无异 稀疏:(3,[0,2],[1.0,3.0])     其表示的含义(向量大小,序号,值 ...

  5. 远程登录工具 —— filezilla(FTP vs. SFTP)、xshell、secureCRT

    filezilla:是一个免费开源的 FTP 软件,分为客户端版本和服务器版本,具备所有的 FTP 软件功能. 支持的协议:FTP & SFTP(Secure File Transfer Pr ...

  6. BZOJ 1391 网络流

    vis[0]没有清零查一年- //By SiriusRen #include <cstdio> #include <cstring> #include <algorith ...

  7. spring boot 集成 mybatis,数据库为mysql

    导入mven工程即可运行,方法不描述了,具体见 https://github.com/davidwang456/spring-boot-mybatis-demo

  8. T4701 【卜卜】树状数组模板

    题目背景 令 夜 色 的 钟 声 响 起 令 黄 昏 (起 始) 的 钟 声 响 起 我 爱 (渴 望) 的 就 只 有 你 我 爱 ( 渴 望 ) 你 正因如此 独自安静地哭泣吧 正因如此 无论你在 ...

  9. Android框架-Volley(二)

    1. ImageRequest的用法 前面我们已经学习过了StringRequest和JsonRequest的用法,并且总结出了它们的用法都是非常类似的,基本就是进行以下三步操作即可: 1. 创建一个 ...

  10. C# 引用DLL版本冲突

    已解决,到官网上下载旧key版本,然后再重定向即可. 手动引用两个版本的DLL错误的原因是我 publicKeyToken 大小写的问题(竟然没校验~~) 但我想不明白,这样搞如果依赖一多的话,甚至那 ...