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>

最新文章

  1. mybatis3.2.3+spring3 控制台打印sql解决办法
  2. [MAC]OS X Mavericks 10.9.5 / 10.10.2 VMWare vmdk镜像,解压就能用!
  3. MYSQL性能调优: 对聚簇索引和非聚簇索引的认识
  4. setup 桌面化设置网卡
  5. iOS UIWebView 捕获403 、404错误
  6. linux 多核
  7. 说一说window.parent
  8. su Authentication failure解决
  9. Asp.Net MVC 2.0 Filter基本用法
  10. JavaScript中Null和Undefined的深渊
  11. TheFourthJavaText
  12. 【转】JavaScript中使用ActiveXObject操作本地文件夹的方法
  13. 使用mongoose和bcrypt实现用户密码加密
  14. 《实战Nginx》读书笔记
  15. mysql 合并left join 数据条目
  16. Vue笔记整理——第一天
  17. quora 的东西就是不一样
  18. supervisorctl 常用命令
  19. oracle 创建create user 及授权grant 查看登陆的用户
  20. 2013-7-27 802.1X学习

热门文章

  1. Elastic Search中DSL Query的常见语法
  2. Spring 容器中 Bean 的生命周期
  3. 怎样解决在执行 vue init 时提示 &quot;vue : 无法加载文件&quot; 的问题?
  4. L1-025. 正整数A+B 简单复习一下,。
  5. z-index神奇的失效了!!!
  6. JS ES5
  7. Linux系统介绍及部署
  8. 阿里巴巴开源框架java诊断工具--Arthas
  9. 【踩坑经历】SQLSTATE[HY000] [2002] Connection refused
  10. Hacklab WebIDE在线调试ESP32笔记