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等于 ...
随机推荐
- Codeforces Round #309 (Div. 1)
A. Kyoya and Colored Balls 大意: 给定$k$种颜色的球, 第$i$种颜色有$c_i$个, 一个合法的排列方案满足最后一个第$i$种球的下一个球为第$i+1$种球, 求合法方 ...
- Ubuntu系统开机后不能正常使用——问题解决记录
1.开机后桌面内容没了,搜狗输入法不能使用了,终端不能打开了 问题原因:上次关机前为了解决解压文件中文乱码问题,在/etc/profile末尾加了如下两行:(但事实上如下两行根本不能解决中文乱码问题) ...
- Visual Studio 2012网站如何只生成一个DLL文件
简介: 在Visual Studio 2005,2008,2010版本中,都有Web Deployment工具将网站进行发布,所有代码文件和库文件发布,生成为一个动态链接库文件,而在Visual St ...
- 【原创】大叔经验分享(59)kudu查看table size
kudu并没有命令可以直接查看每个table占用的空间,可以从cloudera manager上间接查看 CM is scrapping and aggregating the /metrics pa ...
- 【js】clientY pageY screenY layerY offsetY的区别
clientY 指的是距离可视页面左上角的距离 pageY 指的是距离可视页面左上角的距离(不受页面滚动影响) screenY 指的是距离屏幕左上角的距离 layerY 指的是找到它或它父级元素中最近 ...
- djang部署vue项目
1,将vue项目npm run build 在此之前需要修改打包后的js,css文件路径: 需新建vue.config.js 在文件中添加: module.exports = { // 输出目录 as ...
- ES6入门四:对象字面量扩展与字符串模板字面量
简洁属性与简洁方法 计算属性名与[[prototype]] super对象(暂时保留解析) 模板字面量(模板字符串) 一.简洁属性与简洁方法 ES6中为了不断优化代码,减低代码的耦合度在语法上下了很大 ...
- 通俗易懂的axios
get的两种请求: methods:{ //axios.get的发送参数有两种,两个ajax请求函数都可实现 sendGetByStr(){ //1.get通过直接发字符串拼接 axios.get(` ...
- Photoshop从入门到精通所有视频教程(43G)以及素材资料免费拿
包含了Photoshop从入门到精通所有需要了解的视频教程资料,并且包含了大量的P图素材. 资料获取方式,关注公总号RaoRao1994,查看往期精彩-所有文章,即可获取资源下载链接 更多资源获取,请 ...
- 构建虚拟工控环境系列 - 西门子虚拟PLC
一. 概述 跟随着工控安全一路走来,工控安全市场今年明显有相当大的改善,无论从政策还是客户需求,都在逐步扩大中.但是,搞工控安全研究的人员却寥寥无几.一方面工控安全是个跨学课的技术,需要了解多方面的知 ...