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的更多相关文章

  1. Miller-Rabin算法 codevs 1702 素数判定 2

    转载自:http://www.dxmtb.com/blog/miller-rabbin/ 普通的素数测试我们有O(√ n)的试除算法.事实上,我们有O(slog³n)的算法. 定理一:假如p是质数,且 ...

  2. Codevs 1702 素数判定 2(Fermat定理)

    1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...

  3. Miller_Rabin codevs 1702 素数判定2

    /* 直接费马小定理 */ #include<iostream> #include<cstdio> #include<cstdlib> #include<ct ...

  4. codevs——1430 素数判定

    1430 素数判定  时间限制: 1 s  空间限制: 1000 KB  题目等级 : 青铜 Bronze 题解       题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...

  5. 【数论】【素数判定】CODEVS 2851 菜菜买气球

    素数判定模板. #include<cstdio> #include<map> using namespace std; ],ans=-,l,r,n,sum[]; bool is ...

  6. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. HDOJ2012素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  9. hdu 2012 素数判定 Miller_Rabbin

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. java文档

    http://www.boyunjian.com/javadoc/com.dyuproject.protostuff/protostuff-me/1.0.5/_/com/dyuproject/prot ...

  2. 分析Masonry

    一. 继承关系 1.MASConstraint (abstract) MASViewContraint MASComposisionConstraint 2. UIView NSLayoutConst ...

  3. 他们在军训,我在搞 OI(Ending)

    Day 7 上午看看数学书,老师让我把导数相关的概念学了.这也没有多高大上,就是一坨公式需要背,什么 (a)' = 0 啦,什么 (xn)' = n·xn-1 啦,什么 sin'(x) = cos(x ...

  4. git 教程(4)--版本回退

    现在,你已经学会了修改文件,然后把修改提交到Git版本库,现在,再练习一次,修改readme.txt文件如下: Git is a distributed version control system. ...

  5. Ubuntu+Apache+PHP+Mysql环境搭建

    一.操作系统Ubuntu 14.04 64位,虚拟机服务器 二.Apache 1.安装Apache,安装命令:sudo apt-get install apache2 2.环境配置: 1)配置文件:路 ...

  6. struts2回显指定的错误信息

     <s:fielderror />  显示全部的 错误消息(用addFieldError方法添加的 )   <s:fielderror>            <s:pa ...

  7. 初识hibernate小案例

    使用hibernate前需要导入相关JAR包. 1.它可以接受词文法语言描述,并能产生识别这些语言的语句的程序 2.是一个Java的XML API,类似于jdom,用来读写XML文件的 3.支持注解配 ...

  8. [ruby on rails] 深入(2) ruby基本语法

    1. 调试&注释&打印输出 1.1 调试 ruby属于解释型语言,即脚本,在linux上,脚本的执行无非三种: 1. 用解释器运行脚本 解释器 脚本文件 即:ruby  脚本文件 2. ...

  9. 【GoLang】GoLang 遍历 map、slice、array方法

    代码示例: map1 := make(map[string]string) map1["a"] = "AAA" map1["b"] = &q ...

  10. POJ 1062 ( dijkstra )

    http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...