这题用MILLER测试应该是不可避免的。

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <time.h>
#define LL __int64
using namespace std; LL random(LL n){
return (LL)((double)rand()/RAND_MAX*n+0.5);
} LL quick(LL a,LL k,LL m){
LL ans=1;
while(k){
if(k&1){
ans=ans*a%m;
}
k>>=1;
a=a*a%m;
}
return ans;
} bool judgep(LL p){
for(int i=1;i<=15;i++){
LL a=random(p-2)+1;
if(quick(a,p,p)!=a)
return false;
}
return true;
} int main(){
int n;
LL p;
srand(time(0));
while(scanf("%d",&n)!=EOF){
int flag=0;
for(int i=1;i<=n;i++){
scanf("%I64d",&p);
if(judgep(p)){
flag++;
}
}
printf("%d\n",flag);
}
return 0;
}

  

HDU 2138的更多相关文章

  1. HDU 2138 Miller-Rabin 模板题

    求素数个数. /** @Date : 2017-09-18 23:05:15 * @FileName: HDU 2138 miller-rabin 模板.cpp * @Platform: Window ...

  2. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  3. HDU 2138 How many prime numbers

    米勒罗宾素数测试: /* if n < 1,373,653, it is enough to test a = 2 and 3. if n < 9,080,191, it is enoug ...

  4. HDU 2138 How many prime numbers (判素数,米勒拉宾算法)

    题意:给定一个数,判断是不是素数. 析:由于数太多,并且太大了,所以以前的方法都不适合,要用米勒拉宾算法. 代码如下: #include <iostream> #include <c ...

  5. HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. NOI考前乱写

    还有13天NOI,把各种乱七八糟的算法都重新过一遍还是比较有必要的... //HDU 5046 Airport //DancingLink #include<iostream> #incl ...

  8. 【HDU2138】How many prime numbers

    [题目大意] 给n个数判断有几个素数.(每个数<=2^32) 注意多组数据 [题解] 用Rabin_Miller测试跑得飞快... /************* HDU 2138 by chty ...

  9. 【HDU】2138 How many prime numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=2138 题意:给n个数判断有几个素数.(每个数<=2^32) #include <cstdio> ...

随机推荐

  1. 查找python项目依赖并生成requirements.txt——pipreqs 真是很好用啊

    查找python项目依赖并生成requirements.txt 转自:http://blog.csdn.net/orangleliu/article/details/60958525 一起开发项目的时 ...

  2. Truck History --hdoj

    Truck History Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  3. nginx FastCGI模块(FastCGI)配置

    http://www.howtocn.org/nginx:nginx%E6%A8%A1%E5%9D%97%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C%E4%B8%AD%E6 ...

  4. oracle scott趣事

    Oracle里面是scott是个什么用户呢? 这个就要追朔到Oracle的创业阶段了, 1977年6月,埃里森,Bob Miner和Ed Oates在硅谷共同创办了一家名为软件开发实验室(Softwa ...

  5. Three入门学习笔记整理

    一.官方网站:https://threejs.org 二.关于Three.js 三.开始 四.实例 基本结构 结果 五.概念 坐标系 场景 相机 灯光 3D模型 六.简单动画 七.交互控制 结束 # ...

  6. Junit使用第二弹

    实例总结 1. 参数化测试 有时一个测试方法,不同的参数值会产生不同的结果,那么我们为了测试全面,会把多个参数值都写出来并一一断言测试,这样有时难免费时费力,这是我们便可以采用参数化测试来解决这个问题 ...

  7. TOF相机基本知识

    TOF是Time of flight的简写,直译为飞行时间的意思.所谓飞行时间法3D成像,是通过给目标连续发送光脉冲,然后利用传感器接收从物体返回的光,通过探测光脉冲的飞行时间来得到目标物的距离.TO ...

  8. js预览上传图片

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. java中后端拼接字符串返回前台页面换行显示

    后端拼接时用:"\n"分割,比如: String str = "白日依山尽,\n" + "黄河入海流:"; 返回前台页面时,放入 <p ...

  10. Aeroplane chess HDU - 4405_数学期望_逆推

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...