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. 6、Time & Window

    一.Time & Watermark 1.1.DataStream支持的三种time DataStream有大量基于time的operator Flink支持三种time: EventTime ...

  2. 日志分析工具ELK(三)

    目前官网更新特别快,不到半年时间就更新了好几个版本,目前最新的是5.1 以下安装配置使用4.5版本的 https://www.elastic.co/guide/en/kibana/4.5/index. ...

  3. Android:finish()与System.exit(0)之间的区别

    finish()与System.exit(0)都是用来退出.但是两者还是有一定的区别: finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没 ...

  4. 理解分布式一致性:Paxos协议之Generalized Paxos & Byzantine Paxos

    理解分布式一致性:Paxos协议之Generalized Paxos & Byzantine Paxos Generalized Paxos Byzantine Paxos Byzantine ...

  5. SpringBoot 集成Swagger2自动生成文档和导出成静态文件

    目录 1. 简介 2. 集成Swagger2 2.1 导入Swagger库 2.2 配置Swagger基本信息 2.3 使用Swagger注解 2.4 文档效果图 3. 常用注解介绍 4. Swagg ...

  6. vscode快捷替换json格式

    i=json from=AUTO to=AUTO smartresult=dict client=fanyideskweb salt=1537359261311 sign=06b7d1398ebdc6 ...

  7. 乾颐堂7月HCIE、CCIE通过名单

    拼多多都上市了,现在很多培训机构也流行公用一张PASS了,山寨总是山寨的,不脚踏实地总是欺骗自己7月(自然月)乾颐堂通过22名学员,每个考试日通过一名HCIE.CCIE 转载于:https://blo ...

  8. 通过fiddler抓取IDEA的请求

    2019独角兽企业重金招聘Python工程师标准>>> 因为fiddler默认是代理的8888端口,所以设置一下IDEA的请求使用本地的8888作为代理发出. 1."EDI ...

  9. Windows 10配置VS Code C++环境(超详细,面向小白以及大佬们)

    看完这个,还有下一篇:门在这 我看了网上的大佬们配的我是在是看不懂啊?我是一个小白啊?这太难了,这阻挡不了我,想使用这很骚的IDE,于是在不断的摸索下,终于配置成功,小白们也不用慌,这次非常简单.一定 ...

  10. 题目分享Y

    题意:给出一个n个点n条边的图且不一定连通(原题面为每个节点出度为1),相邻节点不能同时被选,每个节点有其对应价值,求最多能获得多少价值?n<=1e6,val[i]<=1e6 分析:很容易 ...