题目链接

题意:题目定义了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. jq层次选择器

    二. 层次选择器 1. parent > child(直系子元素) $(document).ready(function () { // 选取div下的第一代span元素,将字体颜色设为红色 $ ...

  2. A real ROCA using Bootstrap, jQuery, Thymeleaf, Spring HATEOAS and Spring MVC

    http://www.tuicool.com/articles/ENfe2u https://github.com/tobiasflohre/movie-database What is the be ...

  3. 给jdk写注释系列之jdk1.6容器(11)-Queue之ArrayDeque源码解析

    前面讲了Stack是一种先进后出的数据结构:栈,那么对应的Queue是一种先进先出(First In First Out)的数据结构:队列.      对比一下Stack,Queue是一种先进先出的容 ...

  4. Adobe Edge Animate –使用css制作菜单

    Adobe Edge Animate –使用css制作菜单 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 效果图:

  5. hihocoder 1066 无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...

  6. JS轮播图

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. Git CMD - clone: Clone a repository into a new directory

    命令格式 git clone [--template=<template_directory>]  [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare ...

  8. 推荐一款App运营工具:AYL爱盈利App榜单监控

    对包括开发者.产品运营.投资人在内的诸多移动互联网从业人员而言,国内Android应用市场和IOS应用市场的榜单变化数据时大家的必修功课之一:看看这段时间所关注的垂直领域里最火的是哪几款应用:看看竞争 ...

  9. .Net 微信开发与微信支付

    .NET     https://github.com/JeffreySu/WeiXinMPSDK JAVA   http://git.oschina.net/pyinjava/fastweixin ...

  10. web安全实战

    前言 本章将主要介绍使用Node.js开发web应用可能面临的安全问题,读者通过阅读本章可以了解web安全的基本概念,并且通过各种防御措施抵御一些常规的恶意攻击,搭建一个安全的web站点. 在学习本章 ...