素数判定 2(codevs 1702)
一个数,他是素数么?
设他为P满足(P<=263-1)
P
Yes|No
2
Yes
算法导论——数论那一节
注意Carmichael Number
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
LL n;
int s[]={,,,,,,,,,};
LL slowmi(LL a,LL b)
{
LL tot=;
for(LL i=a;i;i>>=)
{
if(i&) tot=(tot+b)%n;
b=(b+b)%n;
}
return tot%n;
}
LL mi(LL a,LL b)
{
LL tot=;
for(LL i=a;i;i>>=)
{
if(i&) tot=slowmi(tot,b)%n;
b=slowmi(b,b)%n;
}
return tot%n;
}
bool check()
{
if(n==) return true;
else if(n<||!(n&)) return false;
for(int i=;i<;i++)//费马小定理10次计算
{
if(n==s[i])return true;
if(mi(n-,s[i])!=) return false;
}
return true;
}
int main()
{
cin>>n;
if(check())printf("Yes");
else printf("No");
return ;
}
素数判定 2(codevs 1702)的更多相关文章
- 【数论】【素数判定】CODEVS 2851 菜菜买气球
素数判定模板. #include<cstdio> #include<map> using namespace std; ],ans=-,l,r,n,sum[]; bool is ...
- Miller-Rabin算法 codevs 1702 素数判定 2
转载自:http://www.dxmtb.com/blog/miller-rabbin/ 普通的素数测试我们有O(√ n)的试除算法.事实上,我们有O(slog³n)的算法. 定理一:假如p是质数,且 ...
- Codevs 1702 素数判定 2(Fermat定理)
1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...
- codevs——1430 素数判定
1430 素数判定 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDOJ2012素数判定
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
- hdu 2012 素数判定 Miller_Rabbin
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 素数判定 AC 杭电
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 杭电ACM 素数判定
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- CSS的相对定位和绝对定位
relative的意思就是相对自己的一开始的位置进行的定位.如图: 但是这个元素的本身边距不变,还在原来位置 absolute的意思就是 如果它的父元素设置了除static之外的定位,比如pos ...
- UVA 10817 - Headmaster's Headache(三进制状压dp)
题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...
- eltwise层
http://blog.csdn.net/u013989576/article/details/73294131 layer { name: "fuse" type: " ...
- 一、numpy入门
Array import numpy as np # create from python list list_1 = [1, 2, 3, 4] array_1 = np.array(list_1)# ...
- OpenCV2:第十一章 图像转换
一.简介 二.例子 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #inclu ...
- TryEnterCriticalSection
if (TryEnterCriticalSection(&g_cs) == FALSE) { 返回 } else { 进入临界区 LeaveCriticalSection(&g_cs) ...
- PAT (Basic Level) Practise (中文)-1036. 跟奥巴马一起编程(15)
PAT (Basic Level) Practise (中文)-1036. 跟奥巴马一起编程(15) http://www.patest.cn/contests/pat-b-practise/103 ...
- CS193p Lecture 9 - Animation, Autolayout
Animation(动画) Demo Dropit续 Autolayout(自动布局) 三种添加自动布局的方法: 使用蓝色辅助虚线,右键选择建议约束(Reset to Suggested Constr ...
- 学习python的第十天(内置算法:列表数据类型,元祖数据类型,字典数据类型)
5.8自我总结 1.列表类型内置算法 1.必须掌握 1.按索引取值(正向取值+反向取值),即可存也可以取 #用于取其中一个值 name = ['yang','wen','yi'] ##正方向取wen, ...
- leepcode作业解析 - 5-20
22.缺失数字 给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数. 示例 1: 输入: [3,0,1] 输出: 2 示例 2: 输入: ...