// Accepted
// Time:: 0.280
#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 10000009
#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;
bool flag[MX];
vector <ull>v;
ull plen;
void seieve()
{
mem(flag,false);
flag[0]=flag[1]=true;
ull i,j,qrt=(unsigned long)sqrt(double(MX));
for(i=4;i<=MX;i+=2)flag[i]=true;
for(i=3;i<=qrt;i+=2)
{
if(!flag[i])
{
for(j=i*i;j<=MX;j+=i+i)
{
flag[j]=true;
}
}
}
for(i=2;i<=MX;i++)
{
if(!flag[i])
{
v.push_back(i);
}
}
plen=v.size();
}
int main()
{
seieve();
ull i;
//lp1(i,plen) cout << v[i] << " ";
int t,tc=1;
sf("%d",&t);
while(t-- and tc++)
{
ull i,n,half,cnt=0;
sf("%llu",&n);
half=n/2;
for(i=0;v[i]<=half;i++)
{
if(!flag[n-v[i]])
{
cnt+=1;
}
}
pf("Case %d: %llu\n",tc-1,cnt);
}
return 0;
}
// Accepted
// Time:: 0.516
#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 10000009
#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;
bool flag[MX];
vector <ull>v;
ull plen;
void seieve()
{
mem(flag,false);
flag[0]=flag[1]=true;
ull i,j,qrt=(unsigned long)sqrt(double(MX));
for(i=4;i<=MX;i+=2)flag[i]=true;
for(i=3;i<=qrt;i+=2)
{
if(!flag[i])
{
for(j=i*i;j<=MX;j+=i+i)
{
flag[j]=true;
}
}
}
for(i=2;i<=MX;i++)
{
if(!flag[i])
{
v.push_back(i);
}
}
plen=v.size();
}
int main()
{
seieve();
ull i;
//lp1(i,plen) cout << v[i] << " ";
int t,tc=1;
sf("%d",&t);
while(t-- and tc++)
{
ull i,n,half,cnt=0;
sf("%llu",&n);
half=n/2;
for(i=0;i<plen;i++)
{
if(v[i] <= half)
{
ull b=n-v[i];
if(!flag[b])
{
if(b>=v[i])
{
cnt+=1;
}
}
}
else break;
}
pf("Case %d: %llu\n",tc-1,cnt);
}
return 0;
}
Comments
Post a Comment