Mathematics:Pseudoprime numbers(POJ 3641)

题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers)
很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是不是素数,然后还有一个很重要的问题,那就是a和p是不互质的,不要用a^(p-1)=1(mod p)这个判据,比如4^6=4(mod 6),但是4^5=4(mod 6)
#include <iostream>
#include <functional>
#include <algorithm> using namespace std;
typedef long long LONG_INT; LONG_INT witness(LONG_INT, LONG_INT, LONG_INT);
bool Is_Prime(LONG_INT); int main(void)
{
LONG_INT coe, n; while (~scanf("%lld %lld", &n, &coe))
{
if (n == && coe == )
break;
if (Is_Prime(n))
printf("no\n");
else if (witness(coe, n, n) == coe)
printf("yes\n");
else
printf("no\n");
}
return ;
} bool Is_Prime(LONG_INT n)
{
for (int i = ; i*i <= n; i++)
{
if (n%i == )
return false;
}
return true;
} LONG_INT witness(LONG_INT coe, LONG_INT level, LONG_INT n)
{
LONG_INT x, y; if (level == )
return ;
x = witness(coe, level >> , n); if (x == )
return ;
y = (x*x) % n;
if (level % == )
y = (coe*y) % n;
return y;
}

Mathematics:Pseudoprime numbers(POJ 3641)的更多相关文章
- poj 3641 Pseudoprime numbers
题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
- poj Pseudoprime numbers 3641
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10903 Accepted: 4 ...
- 【POJ - 3641】Pseudoprime numbers (快速幂)
Pseudoprime numbers Descriptions 费马定理指出,对于任意的素数 p 和任意的整数 a > 1,满足 ap = a (mod p) .也就是说,a的 p 次幂除以 ...
- poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7954 Accepted: 3305 D ...
- HDU 3641 Pseudoprime numbers(快速幂)
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11336 Accepted: 4 ...
- POJ 3641
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6044 Accepted: 24 ...
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- poj 3641 Pseudoprime numbers Miller_Rabin测素裸题
题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...
随机推荐
- git执行pull命令时,报错
在图形界面中,执行拉取操作时,出现下面的错误. You asked to pull from the remote 'origin', but did not specifya branch. Bec ...
- 关于Mysql错误:./bin/mysqld_safe --user=mysql& [1] 32710 121003 16:40:22 mysqld_safe Logging to '/var/log/mysqld.log'. 121003 16:40:22 mysqld_s
[root@www]# ./bin/mysqld_safe --user=mysql&[1] 32710[root@www]# 121003 16:40:22 mysqld_safe Logg ...
- Python 文件遍历
Python具备强大的解析能力,其中列表解析甚至可以作用在某些并非实际存储的序列上,任何可遍历对象都可以,包括可自动逐步读取的文件. 例如下面的代码将会从逐行读取一个文本文件,并且在每一行的最后加上一 ...
- c++模板
1.从 python 说起 def add(a, b): return a + b; print add(3.1, 5.1); #8.2 print add("abc", &quo ...
- etcd
https://github.com/silenceper/dcmp http://studygolang.com/topics/1866
- NHibernate概念
SessionFactory (NHibernate.ISessionFactory) 对属于单一数据库的编译过的映射文件的一个线程安全的,不可变的缓存快照.它是Session的工厂,是Connect ...
- POJ 1925 Spiderman
Spiderman Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5858 Accepted: 1143 Description ...
- CF #305(Div.2) D. Mike and Feet(数学推导)
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- FineUI第十三天---`列布局
这是经典的列布局: <x:Panel runat= <Items> ...
- BZOJ4610——[Wf2016]Ceiling Functi
水题一道,不是很懂为啥没人做... 1.题意:纠正一下..bzoj的题意不是很对...注意不是堆,是不平衡的二叉树,就是非旋转的treap, 另外...插入的时候,小于插在左边..大于等于插在右边 2 ...