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等于 ...
随机推荐
- navicat 使用 pymysql模块
新健库 ,新增字段+类型+约束 设计表:外键(自增) 新建查询 建立表模型 /* 数据导入: Navicat Premium Data Transfer Source Server : localho ...
- java进程CPU高分析
JVM导致系统CPU高的常见场景: 内存不足,JVM gc频繁,一般会伴随OOMJVM某个线程死循环或者递归调用 定位和解决1.内存不足,gc频繁可参考我的这遍文章解决.https://blog.cs ...
- Java EE javax.servlet ServletContainerInitializer接口
ServletContainerInitializer接口 public interface ServletContainerInitializer 一.介绍 该接口,允许在 web 应用程序的启动阶 ...
- Java Web Tomcat服务器
一.Tomcat目录结构 1.bin:存放脚本文件.其中有个档是catalina.bat,打开这个配置文件,在非注释行加入JDK路径(SET JAVA_HOME=C:\j2sdk1.4.2_06)保存 ...
- Flask:上下文管理
1. werkzurg from werkzur.serving import run_simple def run(environ,start_response): reuturn [b'hello ...
- 解压版msyql8.0的安装和配置
一.环境变量配置 变量名:MYSQL_HOME 变量值:D:\mysql-8.0.12-winx64\bin 然后在Path变量开头添加%MYSQL_HOME%:然后确定保存即可: 二.配置my.in ...
- Facebook团队合影
今晚公司年会,晚上有些人不去,我晚上要带孩子,也不去,大家就说那我们中午照个合照吧.没啥子准备,大家都一副油腻的样子.除了要去party的化了妆.
- qt tableview使用
Qt::CheckState checkSibling(QStandardItem * item); void treeItem_checkAllChild(QStandardItem * item, ...
- Advanced Installer 不弹出预安装的软件的窗口
需求:当他电脑上没有sql server client 的时候,或没有localdb的时候,那么安装包会弹出窗口,让他选择 一个组件 一个组件的安装 太麻烦. 有没有办法,打开安装包就安装 安装的过程 ...
- powershell查看版本信息
在终端输入$PSVersionTable