【POJ】3641
来源:互联网 发布:手机电影剪辑软件 编辑:程序博客网 时间:2024/06/15 04:30
http://poj.org/problem?id=3641
满足
①p不是素数
②存在a > 1使得a^p = a (mod p)
的p是伪素数。
现给出p和a,判断p是否是伪素数。
快速幂应用。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <algorithm>using namespace std;__int64 p,a;__int64 qpow(__int64 a,__int64 b){ __int64 mod=b; __int64 ans=1; while (b){ if (b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans;}bool is(__int64 n){ for (__int64 i=2;i*i<=n;i++){ if (n%i==0) return false; } return true;}int main(){ while ((cin >> p >> a)&&(p+a)){ if (is(p)){ cout << "no" << endl; } else if (qpow(a,p)==a){ cout << "yes" << endl; } else{ cout << "no" << endl; } }}
阅读全文
0 0
- poj-3641
- POJ 3641
- 【POJ】3641
- poj 3641解题报告
- POJ-3641-Pseudoprime numbers
- POJ 3641-Pseudoprime numbers
- poj 3641 Pseudoprime numbers
- poj 3641 Pseudoprime numbers
- Miller_Rabin算法 (poj 3641)
- POJ 3641 Pseudoprime numbers
- poj 3641 Pseudoprime numbers
- POJ-3641 Pseudoprime numbers
- POJ 3641 Pseudoprime numbers
- 【POJ 3641】Pseudoprime numbers
- poj 3641 Pseudoprime numbers
- POJ-3641 Pseudoprime numbers
- Pseudoprime numbers POJ 3641
- POJ-----3641快速幂
- Java 自动按键,以及cmd脚本调用
- 自定义控件 类型编辑器
- 自动行为操控Steering(八)—路径跟随(单体操控)
- Eclipse中的动态web项目,项目上报错,有红叉,但是展开项目,找不到哪里报错
- nginx+tomcat
- 【POJ】3641
- 开始写博客了???记录下学习的过程吧
- Tensorflow实现卷积神经网络
- Networking Overview
- Start 1
- 深入理解线程局部变量:ThreadLocal
- java.io.IOException: There appears to be a gap in the edit log. We expected txid 41, but got txid
- 基于结构的或白盒技术
- 一分钟读懂SSM搭建思路(思维导图)