// Verdict :: Accepted
// Time :: 0.109
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf ("%d %d",&a,&b)
#define sfl scanf ("%ld %ld",&a,&b)
#define sfll scanf ("%lld %lld",&a,&b)
#define sfd scanf ("%lf %lf",&a,&b)
#define sff scanf ("%f %f",&a,&b)
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define LL long long
#define L long
#define mem(c,v) memset(c,v,sizeof(c))
#define ui unsigned int
#define ull unsigned long long int
#define nl puts("")
#define sq(x) ((x)*(x))
#define MX 1000005
#define N 100
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define inf 2147483647
#define bn begin()
#define ed end()
using namespace std;
LL prime[MX+10];
bool flag[MX+10],not_cp[MX+10];
LL setbit(LL n, LL pos)
{
n=n|(1<<pos);
return n;
}
bool checkbit(LL n, LL pos)
{
n=n&(1<<pos);
return n;
}
void seieve(LL n)
{
//mem(flag,false);
LL i,j,x=(long) sqrt(double(n));
prime[0]=setbit(prime[0],0);
prime[0]=setbit(prime[0],1);
for(i=4;i<=n;i+=2)
{
prime[i>>5]=setbit(prime[i>>5],i&31);
//flag[i]=true;
}
for(i=3;i<=x;i+=2)
{
if(!checkbit(prime[i>>5],i&31))
{
for(j=i*i;j<=n;j+=i)
{
prime[j>>5]=setbit(prime[j>>5],j&31);
}
}
}
// for(i=2;i<=n;i++)
// {
// if(!checkbit(prime[i>>5],i&31))
// {
// cout << i << " ";
// }
// }
}
void not_compo(LL n)
{
LL i,j; mem(not_cp,false);
mem(flag,false);
for(i=4;i<=n;i++)
{
if(checkbit(prime[i>>5],i&31) and !not_cp[i])
{
for(j=i<<1;j<=n;j+=i)
{
not_cp[j]=true;
}
flag[i]=true;
}
}
// for(i=1;i<=n;i++)
// {
// //cout << flag[i] << " ";
// if(flag[i])
// {
// cout << i << " ";
// }
// }
}
int main()
{
seieve(MX);
not_compo(MX);
LL n;
while(sf("%lld",&n)==1)
{
LL cnt=0;
while(n--)
{
LL x;
sf("%lld",&x);
if(flag[x])
{
cnt+=1;
}
}
pf("%lld\n",cnt);
}
return 0;
}
Comments
Post a Comment