#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <time.h>
#include <map>
#include <algorithm>
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=1000;
const int maxx=1e7+100;
const double EPS=1e-7;
const int mod=998244353;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template<class T> void Scan(T &x)
{
static int CH;
while((CH=getchar())<'0'||CH>'9');
for(x=CH-'0';(CH=getchar())>='0'&&CH<='9';x=(x<<3)+(x<<1)+(CH-'0'));
}
const int s=10;
inline LL mul_mod(LL a, LL b, LL m)
{
LL c = a*b-(LL)((long double)a*b/m+0.5)*m;
return c<0 ? c+m : c;
}
LL fast_exp(LL a,LL x,LL m)
{
LL b = 1;
while (x)
{
if (x & 1)
b = mul_mod(b, a, m);
a = mul_mod(a, a, m);
x >>= 1;
}
return b;
}
bool MR(LL n)
{
if (!(n&1))
return n == 2;
LL t = 0, u;
for (u = n-1; !(u&1); u >>= 1)
++t;
for (int i = 0; i < s; ++i)
{
LL a = rand()%(n-2)+2, x = fast_exp(a, u, n);
for (LL j = 0, y; x != 1 && j < t; ++j, x = y)
{
y = mul_mod(x, x, n);
if (y == 1 && x != n-1)
return false;
}
if (x != 1)
return false;
}
return true;
}
int main()
{
srand();
int t;
while(scanf("%d",&t)!=EOF)
{
int ans=0;
for(int i=1;i<=t;i++)
{
LL x;
Scan(x);
if(MR(x))
ans++;
}
cout<<ans<<endl;
}
}
miller_rabin hdu 2138 判断是否是素数
最新推荐文章于 2018-04-22 15:34:38 发布