Lilght Oj 1259 Goldbach's Conjecture Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
Solution in c++:
#include<bits/stdc++.h>
#define M 10000009
typedef long long ll;
using namespace std;
bool marked[M];
vector<ll>prime;
void sieve(ll n)
{
for(ll i=4; i<=n; i+=2)
marked[i]=true;
for(ll i=3; i*i<=n; i+=2)
{
if(marked[i]==false)
{
for(ll j=i*i; j<=n; j+=i)
{
marked[j]=true;
}
}
}
prime.push_back(2);
marked[2]=false;
for(ll i=3; i<=n; i+=2)
{
if(marked[i]==false)
{
prime.push_back(i);
}
}
}
main()
{
ll n,cnt,k,i,t,d;
sieve(M);
cin>>t;
for(k=1; k<=t; k++)
{
cnt=0;
cin>>n;
for(i=0; prime[i]<=n/2;i++)
{
d=n-prime[i];
if(marked[d]==false)
cnt++;
}
printf("Case %d: %d\n",k,cnt);
}
}
No comments