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. window servet 2012 r2 配置php服务器环境

    绑定:https://jingyan.baidu.com/article/0bc808fc2c6a851bd485b92a.html 配置环境:http://www.jb51.net/article/ ...

  2. umditor删除域名,配置为绝对路径

    getAllPic: function (sel, $w, editor) { var me = this, arr = [], $imgs = $(sel, $w); $.each($imgs, f ...

  3. VirtualBox 原始镜像转换成 vdi 镜像

    VBoxManage convertdd [-static] <filename> <outputfile> 将raw硬盘转换成vdi虚拟硬盘

  4. CSAPP Chapter 8:Exception Control Flow

    prcesssor在运行时,假设program counter的值为a0, a1, ... , an-1,每个ak表示相对应的instruction的地址.从ak到ak+1的变化被称为control ...

  5. log4j 详细解释

    2019独角兽企业重金招聘Python工程师标准>>> 虽然说log4j自己会用,但是还是觉得对配置文件还不是很熟悉,最近看了一个博客,感觉很不多,我提炼出自己的理解. 地址 案例我 ...

  6. 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!

    为什么80%的码农都做不了架构师?>>>   摘要: 近日,阿里云宣布高性能时间序列数据库 (High-Performance Time Series Database , 简称 H ...

  7. CodeForces - 224C. Bracket Sequence (栈模拟)简单做法

    A bracket sequence is a string, containing only characters "(", ")", "[&quo ...

  8. python-CSV格式清洗与转换、CSV格式列变换、CSV格式数据清洗【数据读入的三种方法】【strip、replace、split、join函数的使用】

    1)CSV格式清洗与转换 描述 附件是一个CSV格式文件,提取数据进行如下格式转换:‪‬‪‬‬‪‬‮‬‪‬‭‬ (1)按行进行倒序排列:‪‬‪‬‪‬‪‬‪‬‮‬‬‪‬‮‬‪‬‭‬ (2)每行数据倒序排 ...

  9. vue 之 slot插槽

    插槽,也就是slot,是组件的一块HTML模板,这块模板显示不显示.以及怎样显示由父组件来决定. 实际上,一个slot最核心的两个问题这里就点出来了,父组件决定插槽显示或不显示以及怎样显示,子组件决定 ...

  10. SecureCRT怎么将本级文件上传到CentOS

    进入到想要放文件的路径,不然会默认放在当前路径下: 输入 rz -------------------------------------------------------------------- ...