博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3641 Pseudoprime numbers
阅读量:4707 次
发布时间:2019-06-10

本文共 1527 字,大约阅读时间需要 5 分钟。

Pseudoprime numbers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4864   Accepted: 1872

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-a pseudoprimes, 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 and a.

Output

For each test case, output "yes" if p is a base-a pseudoprime; otherwise output "no".

Sample Input

3 210 3341 2341 31105 21105 30 0

Sample Output

nonoyesnoyesyes

Source

, 2007.9.23
 
//给你一个数 p和一个数 a, 若p是素数输出no,a的p次方模p等于a输出yes,否则输出no
#include 
#include
#include
using namespace std;bool is_prime(int n){
int i,m=sqrt(double(n)); for(i=2;i<=m;i++) if(n%i==0) return 0; return 1;}int main(){
int q,a,tq; __int64 ta,i; while(scanf("%d%d",&q,&a),q||a) {
if(is_prime(q)) {
printf("no\n");continue; } tq=q; i=a; for(ta=1;tq>0;tq=tq>>1,i=(i*i)%q) {
if(tq&1) ta=(ta*i)%q; } if(ta==a) printf("yes\n"); else printf("no\n"); } return 0;}

转载于:https://www.cnblogs.com/372465774y/archive/2012/07/06/2579930.html

你可能感兴趣的文章
android中像素单位dp、px、pt、sp的比较
查看>>
COGS 68. [NOIP2005] 采药【01背包复习】
查看>>
最大流Dinic算法的一些优化 [网络流][最大流]
查看>>
C#——this关键字(2,3)(含求助贴)
查看>>
PAT1002 写出这个数 (C++实现)
查看>>
亚洲物流巨擘获中国投资者入股
查看>>
how to update product listing price sale price and sale date using mobile App
查看>>
hdu 1143
查看>>
Selenium Grid操作使用指南
查看>>
搭建hadoop集群,
查看>>
C++ —— 编译程序
查看>>
Search Binary Tree For Pre Order
查看>>
了解自己的学生,因材施教
查看>>
jquery.color.js
查看>>
huffman编码压缩和解压
查看>>
ssm基础配置
查看>>
jquery 自动运行JS 和如何点击标签运行js 及淡入,淡出效果时 如何附加JS函数
查看>>
mysql备份数据库出错mysqldump: [ERROR] unknown option '--no-beep'
查看>>
删除数据库日志
查看>>
vim替换^m字符
查看>>