poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7954 | Accepted: 3305 |
Description
Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power
and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as base-apseudoprimes, have this property for some a. (And some, known as Carmichael Numbers, are base-a pseudoprimes
for all a.)
Given 2 < p ≤ 1000000000 and 1 < a < p, determine whether or not p is a base-a pseudoprime.
Input
Input contains several test cases followed by a line containing "0 0". Each test case consists of a line containing p anda.
Output
For each test case, output "yes" if p is a base-a pseudoprime; otherwise output "no".
Sample Input
3 2
10 3
341 2
341 3
1105 2
1105 3
0 0
Sample Output
no
no
yes
no
yes
yes
<span style="font-size:32px;">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
long long a,p;
long long power(long long a,long long p)
{
long long ret=1,temp=p;
while(temp)
{
if(temp&1)
ret=(ret*a)%p;
a=(a*a)%p;
temp>>=1;
}
return ret%p;
}
bool prime(long long m)
{
for(long long i=2;i*i<=m;i++)
if(m%i==0)
return false;
return true;
}
int main()
{
long long a,p;
while(~scanf("%lld %lld",&p,&a))
{
if(a==0&&p==0) return 0;
if(power(a,p)==a%p&&!prime(p))
printf("yes\n");
else
printf("no\n");
}
return 0;
}
</span>
poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题的更多相关文章
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
- poj 3641 Pseudoprime numbers
题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...
- poj 3641 Pseudoprime numbers(快速幂)
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- POJ 3641 Pseudoprime numbers (miller-rabin 素数判定)
模板题,直接用 /********************* Template ************************/ #include <set> #include < ...
- poj 3641 Pseudoprime numbers Miller_Rabin测素裸题
题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...
- POJ 3070 Fibonacci 矩阵快速幂模板
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18607 Accepted: 12920 Descr ...
- HDU 3641 Pseudoprime numbers(快速幂)
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11336 Accepted: 4 ...
- 【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)
-->Carmichael Numbers Descriptions: 题目很长,基本没用,大致题意如下 给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于 ...
随机推荐
- Stardew Valley(星露谷物语)Mod开发之路 写在前面
之前迷上了一款新游戏Stardew Valley,这几天发现游戏为插件开发提供了SMAPI编程接口,玩家可以方便的自定义游戏内容(瞬间感觉因缺思厅,额..),其实这几年的游戏许多都有mod机制,商家机 ...
- PostgreSQL查看表、表索引、视图、表结构以及参数设置
-- 表索引select * from pg_indexes where tablename='person_wechat_label';select * from pg_statio_all_ind ...
- CVPR2019目标检测方法进展综述
CVPR2019目标检测方法进展综述 置顶 2019年03月20日 14:14:04 SIGAI_csdn 阅读数 5869更多 分类专栏: 机器学习 人工智能 AI SIGAI 版权声明:本文为 ...
- Lua的API函数
1. 基础库 我们在整个教程中使用了各种主题下的基本库. 下表提供了相关页面的链接,并列出了本Lua教程各部分所涵盖的功能. 编号 库/方法 作用 1 错误处理 包括错误处理函数,如断言, 错误,如L ...
- [C#.net]连接Oracle的几种方式
一:通过System.Data.OracleClient(需要安装Oracle客户端并配置tnsnames.ora)1. 添加命名空间System.Data.OracleClient引用2. usin ...
- Java高并发程序设计学习笔记(十一):Jetty分析
转自:https://blog.csdn.net/dataiyangu/article/details/87894253 new Server()初始化线程池QueuedThreadPoolexecu ...
- IDEA springboot maven 项目部署
- Web自动化测试中的接口测试
1.2.3 接口可测性分析 接口显而易见要比UI简单的都,只需要知道协议和参数即可完成一次请求,从自动化测试实施难易程度来看,有以下几个特征: 1)驱动执行接口的自动化成本不高:HTTP,RPC,SO ...
- 《设计模式之美》 <01>为什么需要学习掌握设计模式?
1. 应对面试中的设计模式相关问 题学习设计模式和算法一样,最功利.最直接的目的,可能就是应对面试了.不管你是前端工程师.后端工程师,还是全栈工程师,在求职面试中,设计模式问题是被问得频率比较高的一类 ...
- getAttribute和getParameter的简单区别
getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...