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. android 弹出的软键盘遮挡住EditText文本框的解决方案

    1.android 弹出的软键盘遮挡住EditText文本框的解决方案: 把Activit对应的布局文件filename.xml文件里的控件用比重设置布局.(例如:android:layout_wei ...

  2. [BZOJ1999][codevs1167][Noip2007]Core树网的核

    [BZOJ1999][codevs1167][Noip2007]Core树网的核 试题描述 设T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边带有正整数的权,我们称T为树网(t ...

  3. pro*c添加SQLCHECK后编译报错PLS-S-00201

    如果在pro*c中调用数据库了里的函数,就需要在proc的cfg配置文件中添加一行: SQLCHECK=SEMANTICS 但是添加之后又会出现PLS-S-00201错误,原因在与添加SQLCHECK ...

  4. C++基础知识(2)---函数

    c++中的函数和C语言中的函数相比,增加了许多新的语法与功能.在这里总结一下c++中常用的引用函数,函数重载和内联函数. 1  引用参数 引用参数最常用的一个例子就是 交换 两个数,如下 void s ...

  5. Python学习笔记一

    原来Python的文件配置好环境变量直接双击就可以运行,当然也可以控制台+编辑器 first try: import turtle window=turtle.Screen() babbage=tur ...

  6. BZOJ 4531: [Bjoi2014]路径

    Description 一个无向图,每个节点有一个字符,问形成长度为k的的合法表达式的方案数. Sol DP. \(f[i][o][p][0/1]\) 表示走 \(i\) 步,到 \(o\) ,有 \ ...

  7. Android 手势水平监听判断

    package com.zihao.ui; import com.zihao.R; import android.os.Bundle; import android.app.Activity; imp ...

  8. putty快速设置本地代理

    sudo plink -D 127.0.0.1:8888 -l root -P 443 -pw xxx 104.xxx.xxx.xxx

  9. extjs动态改变样式

    { width:438, height:440, name:'loginDiv', ui:'123', x: '50%' , y: 200, border:true, bodyStyle:{ 'bor ...

  10. n全排列输出和 n个数的组合(数字范围a~b)

    n全排列输出: int WPermutation(int num, bool bRepeat) num表示num全排列 bRepeat标志是否产生重复元素的序列. int Permutation(in ...