【题目大意】

给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. vue-router教程二(要素篇之新手入门)

    注意,我们将在指南中使用es 2015代码样本.此外,所有示例都将使用VUE的完整版本来使在线模板编译成为可能.请参阅这里的更多细节. 用vue路由器创建单页应用程序是非常简单的.使用vue.js,我 ...

  2. filter敏感词替换

    1.properties文件的应用 在<filter>写入配置 <filter> <filter-name>myFilter</filter-name> ...

  3. Codeforces Round #205 (Div. 2)C 选取数列可以选择的数使总数最大——dp

    http://codeforces.com/contest/353/problem/C Codeforces Round #205 (Div. 2)C #include<stdio.h> ...

  4. EF6:编写你自己的code first 数据迁移操作(睡前来一篇,翻译的)

    原英文版由EF团队成员 Rowan Miller 在2013年发表,此处只作翻译备忘. 数据迁移提供了一套强类型API,用于执行通用的操作,比如CreateIndex("dbo.Blogs& ...

  5. 3、MR开发入门

    1.预先准备2个文件file1.txt和file2.txt.文件内容为网页上摘下,不具有代表性,只为举例. file1.txt内容为: With this setup, whenever you ch ...

  6. Vue.js实现数据的双向数据流

    众所周知,Vue.js一直使用的是单向数据流的,和angularJs的双向数据流相比,单向数据流更加容易控制.Vue.js允许父组件通过props属性传递数据到子组件.但是有些情况下我们需要在子组件里 ...

  7. FPGA之外,了解一下中断

    中断是什么? 中断的汉语解释是半中间发生阻隔.停顿或故障而断开.那么,在计算机系统中,我们为什么需要“阻隔.停顿和断开”呢? 举个日常生活中的例子,比如说我正在厨房用煤气烧一壶水,这样就只能守在厨房里 ...

  8. (转)winform安装项目、安装包的制作、部署

    本文转载自:http://zhan.renren.com/cxymst?gid=3602888498037535727&from=post&checked=true 1,解决方案—添加 ...

  9. python 高阶内置函数

    1.lambda 匿名函数 lambda 参数: 返回值 函数名统一都叫lambda. 2.sorted() 排序函数 排序函数 sorted(iterable,key,reverse) key:排序 ...

  10. idea 注册码 地址:

    http://idea.lanyus.com IntelliJ IDEA 注册码 *.lanyus.com及*.qinxi1992.cn下的全部授权服务器已遭JetBrains封杀 请搭建自己的Int ...