【题目大意】

给n个数判断有几个素数。(每个数<=2^32)

注意多组数据

【题解】

用Rabin_Miller测试跑得飞快。。。

 /*************
HDU 2138
by chty
2016.11.5
*************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,ans;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
ll fast(ll a,ll b,ll mod) {ll sum=;for(;b;b>>=,a=a*a%mod)if(b&)sum=sum*a%mod;return sum;}//一行快速幂
bool Rabin_Miller(ll p,ll a)
{
if(p==) return ;
if(p&==||p==) return ;
ll d=p-;
while(!(d&)) d>>=;
ll m=fast(a,d,p);
if(m==) return ;
while(d<p)
{
if(m==p-) return ;
d<<=;
m=m*m%p;
}
return ;
}
bool isprime(ll x)
{
static ll prime[]={,,,,,,,,};
for(ll i=;i<;i++)
{
if(x==prime[i]) return ;
if(!Rabin_Miller(x,prime[i])) return ;
}
return ;
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
while(~scanf("%lld",&n))
{
ans=;
for(ll i=;i<=n;i++)
{
ll x=read();
if(isprime(x)) ans++;
}
printf("%lld\n",ans);
}
return ;
}

【HDU2138】How many prime numbers的更多相关文章

  1. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

  2. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  3. 【CF653G】Move by Prime 组合数

    [CF653G]Move by Prime 题意:给你一个长度为n的数列$a_i$,你可以进行任意次操作:将其中一个数乘上或者除以一个质数.使得最终所有数相同,并使得操作数尽可能小.现在我们想要知道$ ...

  4. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  5. 【Codeforces 385C】Bear and Prime Numbers

    [链接] 我是链接,点我呀:) [题意] f[i]表示在x[]中有多少个数字是i的倍数 让你求出sum(f[i]) li<=i<=ri 且i是质数 [题解] 做筛法求素数的时候顺便把素数i ...

  6. 【leetcode】Bitwise AND of Numbers Range(middle)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. 【LeetCode】165 - Compare Version Numbers

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  8. 【leetcode】448. Find All Numbers Disappeared in an Array

    problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...

  9. 【Leetcode】445. Add Two Numbers II

    You are given two non-empty linked lists representing two non-negative integers. The most significan ...

随机推荐

  1. autoconf 简单demo试用

    1. 安装工具 yum install -y automake   2. 基本项目 a. 项目参考结构 ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefi ...

  2. spec.template.spec.initContainers[1].securityContext.privileged: Forbidden: disallowed by policy 问题解决

    主要是执行系统特权应用解决方法: api server   controller-manager 加上  --allow-privileged=true 即可 之后重启服务  

  3. 如何查看你的 FastAdmin 服务器是否开启了 gzip br 压缩

    如何查看你的 FastAdmin 服务器是否开启了 gzip 压缩 gzip br 压缩的好处不用多说了. 但是怎么方便的知道网站到底有没有开启或使用了 gzip 呢,其实只要在浏览器就可以看到. 按 ...

  4. 【转】无需root Android 4.4现已支持显示电量百分比

    原文网址:http://android.tgbus.com/shouji/news/201311/481145.shtml 现如今,大多数安卓设备.第三方ROM都可以在状态栏以百分比的形式精确显示剩余 ...

  5. Oracle12c之 CDB数据库中数据字典架构

    数据字典就是元数据的集合,比如创建的表,列,约束,触发器等等这些都是元数据,需要保存到数据库中.除此之外,Oracle自身的一些数据库对象,如目录,PL/SQL代码等等这些都是元数据,都需要存放在数据 ...

  6. bzoj1087互不侵犯King(状压)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1087 简单的状压dp.但是wa了好几发.注意long long. 注意0和0的连边.而且不能 ...

  7. winform 控件随页面大小进行自适应

    这个功能网上很多人在问,也有不少人给出过答案,经过实际使用,觉得网上这段代码实现的效果比较好,记录一下 核心代码就是下面这个类 using System; using System.Collectio ...

  8. 在单片机上实现UDP

    http://blog.chinaunix.net/uid-18921523-id-260999.html

  9. python--logging库学习_自我总结---有空完善

    思路: 1.把前面的都封装,然后在测试用例里面调用,每一步测试步骤下面都加一个  logging.info('这个是测试步骤')(可以 亲测) 2.尝试添加到unittest框架里面,看能不能一起使用 ...

  10. kotlin学习二:初步认识kotlin

    1. 函数 kotlin中支持顶级函数(文件内直接定义函数),对比JAVA来说,JAVA的程序入口是main方法,kotlin也一样,入口为main函数 首先看下kotlin中main函数的定义. f ...