POJ 3641
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6044 | Accepted: 2421 |
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 2
10 3
341 2
341 3
1105 2
1105 3
0 0
Sample Output
no
no
yes
no
yes
yes
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; typedef long long ll; int p,a; bool judge() {
for(int i = ; i * i <= p; i++) {
if(p % i == ) return false;
} return true;
}
bool mod_pow(ll x,ll n) {
ll res = ;
while(n > ) {
if(n & ) res = res * x % p;
x = x * x % p;
n >>= ;
} return res == a;
} int main() {
//freopen("sw.in","r",stdin); while(~scanf("%d%d",&p,&a) && p && a) {
if(!judge() && mod_pow(a,p)) printf("yes\n");
else printf("no\n"); } return ;
}
POJ 3641的更多相关文章
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
- POJ 3641 快速幂+素数
http://poj.org/problem?id=3641 练手用,结果念题不清,以为是奇偶数WA了一发 #include<iostream> #include<cstdio> ...
- poj 3641 Pseudoprime numbers
题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...
- poj 3641 Pseudoprime numbers Miller_Rabin测素裸题
题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...
- poj 3641 ——2016——3——15
传送门:http://poj.org/problem?id=3461 题目大意:给你两个字符串p和s,求出p在s中出现的次数. 题解:这一眼看过去就知道是KMP,作为模板来写是最好不过了.... 这道 ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- Mathematics:Pseudoprime numbers(POJ 3641)
强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是 ...
- Pseudoprime numbers(POJ 3641 快速幂)
#include <cstring> #include <cstdio> #include <iostream> #include <cmath> #i ...
- poj 3641 Pseudoprime numbers(快速幂)
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
随机推荐
- 济南学习 Day 2 T2 pm
她[问题描述]给你L,R,S,M,求满足L≤ (S × x) mod M ≤ R最小的正整数 X.[输入格式]第一行一个数T代表数据组数.接下来一行每行四个数代表该组数据的L,R,S,M.[输出格式] ...
- hidden(隐藏域)
<input type="hidden">? 这等于是隐藏值,客户端无需显示,但提交后后台能够接受,例如你放个表单验证值在里边,这样可以拒绝来源不明的表单提交.还有判断 ...
- VC按钮控件实现指示灯效果
VC为按钮控件添加图片的方法有很多种: 直接调用SetBitmap: CButton pButton->SetBitmap(hBitmap); 使用CButtonST控件: 使用CDC: 使用 ...
- 【风马一族_Android】Android 从命令行界面获取手机信息
Android 从命令行界面获取手机信息 1: cmd 打开命令行界面 2:adb devices 获取与电脑相连的设备,例如:模拟器.真机(手机) (右击“标记”,选择设备名称,点击“Ctrl+ ...
- 删除所有表数据的sql语句
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' EXEC sp_MSForEachTable 'ALTER TABLE ? ...
- jar 命令打war包
假定有一个Web应用:C:\myHomemyHome/WEB-INF/……myHome/files/……myHome/image/……myHome/src/……myHome/index.jsp在命令行 ...
- SVN四部曲之SVN使用详解进阶
SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...
- Android系统SVC命令教程
svc命令,位置在/system/bin目录下,用来管理电源控制,无线数据,WIFI # svc svc Available commands: help Show information about ...
- c++内存分配
[导语] 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对C++的痛恨,但内存管理在C++中无处不 ...
- IOS开发一些资源收集
从别的地方看到的,多谢作者,现贴在这里备忘. 在线教程 iOS技术概述 我个人感觉这是开始iOS开发第一步,了解一下iOS整体的结构,有哪些支持类库.如何使用类库等等一切基础的概念性指示 iPh ...