hdu2138 How many prime numbers

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll; ll prime[] = {,,,,};
ll qmul(ll a, ll b, ll mod) {
ll res = ;
while (b) {
if (b&) res = (res+a)%mod;
a = (a+a)%mod;
b >>= ;
}
return res;
}
ll qpow(ll a, ll b, ll mod) {
ll res = ;
while (b) {
if (b&) res = qmul(res,a,mod);
a = qmul(a,a,mod);
b >>= ;
}
return res;
}
bool Miller_Rabin(ll p) {
if (p < ) return ;
if (p != && p % == ) return false;
ll s = p-;
while (!(s&)) s >>= ;
for (int i = ; i < ; i++) {
if (p == prime[i]) return true;
ll t = s, m = qpow(prime[i],s,p);
while (t != p- && m != && m != p-) {
m = qmul(m,m,p);
t <<= ;
}
if (m != p- && !(t&)) return false;
}
return true;
}
int main() {
int n;
while (~scanf("%d",&n)) {
int ans = ;
for (int i = ; i <= n; i++) {
ll x; scanf("%lld",&x);
if (Miller_Rabin(x)) ans++;
}
printf("%d\n",ans);
}
return ;
}

hdu2138 How many prime numbers 米勒测试的更多相关文章

  1. Project Euler 41 Pandigital prime( 米勒测试 + 生成全排列 )

    题意:如果一个n位数恰好使用了1至n每个数字各一次,我们就称其为全数字的.例如,2143就是一个4位全数字数,同时它恰好也是一个素数. 最大的全数字的素数是多少? 思路: 最大全排列素数可以从 n = ...

  2. 2018.12.17 hdu2138 How many prime numbers(miller-rbin)

    传送门 miller−rabbinmiller-rabbinmiller−rabbin素数测试的模板题. 实际上miller−rabinmiller-rabinmiller−rabin就是利用费马小定 ...

  3. [HDU2138]How many prime numbers

    来源: HDU 2007-11 Programming Contest_WarmUp 题目大意:素数判定. 思路: 事实上暴力判定也可以过,但我还是用了Miller-Rabin算法. 核心思想:利用费 ...

  4. CSU 1552 Friends(二分图 + 米勒测试)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552 Description On an alien planet, every e ...

  5. poj 2739 Sum of Consecutive Prime Numbers 尺取法

    Time Limit: 1000MS   Memory Limit: 65536K Description Some positive integers can be represented by a ...

  6. Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )

    题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  9. algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )

    Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...

随机推荐

  1. POJ1475 推箱子---模块化思想

    自古逢秋悲寂寥,我言秋日胜春朝. 晴空一鹤排云上,便引诗情到碧霄. --刘禹锡 题目:推箱子 网址:http://poj.org/problem?id=1475 推箱子游戏相信大家都不陌生,在本题中, ...

  2. JDK11的重要新特性

    文章目录 JDK11发布啦 Oracle不再提供JRE和Server JRE下载 删除部署工具 JavaFX不再包含在JDK中 删除Java EE和CORBA模块 JDK11发布啦 JDK11 在20 ...

  3. 数据库SQL语言从入门到精通--Part 4--SQL语言中的模式、基本表、视图

    数据库从入门到精通合集(超详细,学习数据库必看) 前言: 使用SQL语言时,要注意SQL语言对大小写并不敏感,一般使用大写.所有符号一定是西文标点符号(虽然是常识,但我还是提一嘴) 1.模式的定义与删 ...

  4. 图论--双连通E-DCC缩点模板

    // tarjan算法求无向图的桥.边双连通分量并缩点 #include<iostream> #include<cstdio> #include<cstring> ...

  5. 跟哥一起学python(3)- 理解“变量”

    我们把前面的程序稍微改一下,来了解python中的变量. # file: ./4/4_1.py # 定义变量 hello_str = "hello, world!" # 字符串打印 ...

  6. zabbix监控nginx日志状态码

    监控需求 监控Nginx常见的状态码并对其进行监控,对常见的错误状态码创建相对应的触发器以下按照分钟对数据进行抓取 Zabbix_Agentd创建监控脚本 1)创建脚本之前核对Nginx日志格式我这里 ...

  7. Docker 快速安装Jenkins完美教程 (亲测采坑后详细步骤)

    一.前言 有人问,为什么要用Jenkins,在一些中小型企业?我说下我以前开发的痛点,每次开发一个项目完成后,需要打包部署,可能没有专门的运维人员,只能开发人员去把项目打成一个war包,可能这个项目已 ...

  8. libevent(六)事件监听

    libevent是如何实现事件监听的呢? 在Linux,libevent的底层实现是epoll,因此实现事件监听的方式就是,把需要监听的fd加入epoll中. I/O事件 定时器事件 定时器事件没有f ...

  9. windows下flume 采集如何支持TAILDIR和tail

    一.问题:Windows 下 flume采集配置TAILDIR的时候,会报如下错误: agent.sources.seqGenSrc.type = TAILDIR agent.sources.seqG ...

  10. 数位dp H - F(x) HDU - 4734

    http://acm.hdu.edu.cn/showproblem.php?pid=4734 一般数位dp表示的是数的性质,这个题目也是一样,但是我们求出来的是一个函数的值,怎么把这个值转化成一类数, ...