[ create a new paste ] login | about

Link: http://codepad.org/xUsZpExK    [ raw code | output | fork ]

iamyeasin - C++, pasted on Jan 26:
#include<bits/stdc++.h>
#define MAX 10000

using namespace std;


static long long int p[MAX];
static long long int prime[MAX];

void seive()
{
    memset(p,0,sizeof(p));
    for(int i=4; i<= MAX; i+=2)
    {
        p[i] = 1; // evens are not prime.1 means not prime. 0 means prime
    }

    for(int i=3; i*i<MAX; i+=2)
    {
        if(!p[i])
        {
            for(int j=i*i; j<MAX; j+=i)
            {
                p[j] = 1;// Cutting the factors which is not prime.
            }
        }
    }

    prime[0]=2;
    int k=1;
    for(int i=3; i<MAX; i++)
    {
        if(!p[i])
        {
            prime[k]=i; //storing the primes.
            k++;
        }
    }
}

int main()
{
    seive();
    int n,counter;

    while(scanf("%d",&n) != EOF)
    {
        counter=0;
        if(n>=4 && !(n&1))
        {
            for(int i=0; i<n; i++)
            {
                for(int j=1; j<n; j++)
                {
                    if(prime[i] + prime[j] == n)
                    {
                        counter++;
                    }
                }
            }
        }
        cout<<counter<<endl;
    }


    return 0;
}


Output:
1
2
3
Line 23: error: bits/stdc++.h: No such file or directory
Line 7: error: ISO C++ does not support 'long long'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: