codevs 1702素数判定2
Miller-Rabin算法实现,但是一直被判题程序搞,输入9999999999得到的结果分明是正确的但是一直说我错
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime> using namespace std; typedef long long LL;
LL gcd(LL x, LL y)
{
if (!y) return x;
return (y, x%y);
}
LL pow(LL a, LL x, LL mod)
{
LL ans = ;
while(x)
{
if (x & ) (ans *= a) %= mod;
(a *= a) %= mod;
x >>= ;
}
return ans;
}
bool MRT(LL x)
{
if (x == ) return true;
for (LL i = ; i <= ; ++i)
{
LL now = rand()%(x-) + ;
if (pow(now, x-, x) != ) return false;
}
return true;
}
int main()
{
int n;
LL x;
while(scanf("%I64d", &x)!=EOF)
{
if(x==)
printf("No\n");
else if(x==)
printf("No\n");
else
{
if (MRT(x))
printf("Yes\n");
else
printf("No\n");
}
} return ;
}
codevs 1702素数判定2的更多相关文章
- 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< ...
- Miller_Rabin codevs 1702 素数判定2
/* 直接费马小定理 */ #include<iostream> #include<cstdio> #include<cstdlib> #include<ct ...
- codevs——1430 素数判定
1430 素数判定 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...
- 【数论】【素数判定】CODEVS 2851 菜菜买气球
素数判定模板. #include<cstdio> #include<map> using namespace std; ],ans=-,l,r,n,sum[]; bool is ...
- 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 ...
随机推荐
- 又一个绝对棒的对话框插件fancybox v1.3.4
http://www.jsfoot.com/jquery/demo/2011-07-30/fancybox/index.html jquery插件:fancybox Fancybox的特点如下: ...
- iOS开发——高级篇——iOS键盘的相关设置(UITextfield)
一.键盘风格 UIKit框架支持8种风格键盘. typedef enum { UIKeyboardTypeDefault, // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapa ...
- iOS开发——UI基础-按钮的创建和设置
@interface ViewController () - (IBAction)customBtnClick; @end @implementation ViewController - (void ...
- CF570D——Tree Requests
1.题目大意:给你一棵树,每个点有一个字符,然后我们定义1的深度是1,然后1的儿子深度是2... 然后有一个询问,询问以i为根节点的子树,然后深度是k的那层的所有字符,可否组成一个回文串 2.分析:首 ...
- leetcode 33. Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- python trackback的使用心得
以前在读代码的时候总是要花很久时间去找在哪里调用的某个函数,现在好了,直接使用:trackback.print_stack()就可以打印出调用栈了,在那个地方调用的一目了然... 而如果是异常栈的话就 ...
- python日志浅析
输出日志对于追踪问题比较重要. 默认logger(root) python使用logging模块来处理日志.通常下面的用法就能满足常规需求: import logging logging.debug( ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- phalcon 前端代码结构
phalcon 前端举例: (1) baisic.phtml + basic_ajax_get.phtml + basic_ajax_post.phtml (2) basic_get.phtml ...
- linux上进程状态查询
linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有 ...