题目链接

题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数。之后输入p,a问p是否为Carmichael Numbers?

坑点:先是各种RE,因为poj不能用srand()...之后各种WA..因为里面(a,p) ?= 1不一定互素,即这时Fermat定理的性质并不能直接用欧拉定理来判定。。即 a^(p-1)%p = 1判断是错误的。。作的

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
typedef long long ll;
int T,kase = ,i,j,k,n,m;
ll mult(ll x,ll y,ll mod) // ·ÀÖ¹x*y±¬long long;
{
ll ans = ;x %= mod;
while(y){
if(y&) ans += x, y--;
if(ans >= mod) ans -= mod;
y >>= ;
x <<= ;
if(x >= mod) x -= mod;
}
return ans;
}
ll pow(ll a,ll n,ll mod)
{
a %= mod;
ll ans = ;
while(n){
if(n&) ans = ans*a%mod;
a = a*a%mod;
n >>= ;
}
return ans;
}
int p[]={,,,,,,,,,,,,,,,};
bool Miller_Rabin(ll n)
{
if(n <= ) return n == ;
if(n% == ) return false;
ll t = n - ;
while(t% == ) t >>= ;
for(int i = ;i < ;i++){
if(p[i] >= n) return true;
if(n % p[i] == ) return false;
ll tmp = t;
ll x = pow(p[i],t,n); // p[i]^t % n;
while(tmp < n){
ll y = mult(x,x,n);
if(y == && x != && x != n-) return false;
x = y;
tmp <<= ;
}
if(x != ) return false; // Fermat theory
}
return true;
}
int main()
{
ll x,y;
while(read2(x,y), x + y){
if(Miller_Rabin(x) || pow(y,x,x) != y) puts("no");
else puts("yes");
}
return ;
}

poj 3641 Pseudoprime numbers Miller_Rabin测素裸题的更多相关文章

  1. poj 3641 Pseudoprime numbers

    题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...

  2. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  3. poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题

    Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7954 Accepted: 3305 D ...

  4. poj 3641 Pseudoprime numbers(快速幂)

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  5. POJ 3641 Pseudoprime numbers (miller-rabin 素数判定)

    模板题,直接用 /********************* Template ************************/ #include <set> #include < ...

  6. HDU 3641 Pseudoprime numbers(快速幂)

    Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11336   Accepted: 4 ...

  7. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

  8. POJ 2234 Matches Game(Nim博弈裸题)

    Description Here is a simple game. In this game, there are several piles of matches and two players. ...

  9. POJ 2031 Building a Space Station (prim裸题)

    Description You are a member of the space station engineering team, and are assigned a task in the c ...

随机推荐

  1. Debian 7 安装 Python3.4

    Debian 7 自带的python是2.7.3,要用最新的3.4版本怎么办?我们从官网下载压缩包自己编译. 一.安装编译用的包 $ sudo apt-get install build-essent ...

  2. 使用 collectionView 实现表头,区头,区尾

    UICollectionView 的使用是跟表的使用是一样,瀑布流的布局会比表的效果更好,这里说一下 collectionView 设置表头, 区头,区尾 设置表头可以约束 collectionVie ...

  3. git 在windows上 生成ssh公钥

    今天上传代码到服务器时,报如下错误:   上网搜了一下,应该是ssh过期了.我们就来生成新的ssh公钥吧.   1. 打开git bash   2. 输入命令:  ssh-keygen -t rsa ...

  4. KindEditor图片上传到七牛云

    自己做了一个网站,编辑器用的是KindEditor,平时会涉及到KindEditor自带的图片上传,但是服务器用的是虚拟主机,没多少空间,就一直想着把图片放在免费的云存储空间,之前看KindEdito ...

  5. python 基础——*args和**kwargs

    *args表示任何多个无名参数,它是一个tuple:**kwargs表示关键字参数,它是一个dict. def func(one, *args, **kwargs): print type(one) ...

  6. pgpool postgresql集群、中间件

    pgpool-II是一个工作于PostgreSQL服务器端和PostgreSQL客户端之间的中间件,它提供了如下的功能: 1.连接池 pgpool-II中保存了到PostgreSQL服务器的连接,然后 ...

  7. oracle checkpoint 详解

    Oracle checkpoint详解 topcheckpoint扫盲 top什么是checkpoint 在数据库系统中,写日志和写数据文件是数据库中IO消耗最大的两种操作,在这两种操作中写数据文件属 ...

  8. LeetCode 203

    Remove Linked List Elements Remove all elements from a linked list of integers that have value val. ...

  9. Html5中的video元素

    最近在做门户的时候遇到要显示企业的视频介绍,需要找到一个在aspx页面播放视频的html,最后找到了是一段HTML5最新的html代码,如下: /// <summary> /// 播放视频 ...

  10. java开发:分享一下使用urlrewrite实现网址的个性访问

    很多网站都有一些比较个性的域名访问方式,如:http://www.xxx.com/u/pp  点开就可以看到pp的个人主页了,这种地址比较容易让人记住,那今天就来讲讲这种技术的实现方式. 1.使用ja ...