AC通道:http://vjudge.net/problem/HDU-2138
【题目大意】
给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=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll fast(ll a,ll b,ll mod) {ll sum=1;for(;b;b>>=1,a=a*a%mod)if(b&1)sum=sum*a%mod;return sum;}//一行快速幂
bool Rabin_Miller(ll p,ll a)
{
if(p==2) return 1;
if(p&1==0||p==1) return 0;
ll d=p-1;
while(!(d&1)) d>>=1;
ll m=fast(a,d,p);
if(m==1) return 1;
while(d<p)
{
if(m==p-1) return 1;
d<<=1;
m=m*m%p;
}
return 0;
}
bool isprime(ll x)
{
static ll prime[9]={2,3,5,7,11,13,17,19,23};
for(ll i=0;i<9;i++)
{
if(x==prime[i]) return 1;
if(!Rabin_Miller(x,prime[i])) return 0;
}
return 1;
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
while(~scanf("%lld",&n))
{
ans=0;
for(ll i=1;i<=n;i++)
{
ll x=read();
if(isprime(x)) ans++;
}
printf("%lld\n",ans);
}
return 0;
}