You are not logged in. Please login at www.codechef.com to post your questions!

×

Levy Conjecture, Sieve of Eratosthenes,TLE problem.

link: http://www.codechef.com/problems/LEVY/

include<stdio.h>

include<stdlib.h>

include<math.h>

int main() {

int t;
scanf("%d",&t);
while(t--)
{
    int n;
    scanf("%d",&n);
    int  A[n],i;
    for(i=2;i<n;i++)//sieve_start
    {   
        A[i]=i;
    }
    int p;
    for(p=2;p<n;p++)
    {
        if(A[p]!=0)
        {
            for(i=p;i*p<n;i++)
            {
                A[i*p]=0;//'0'->not prime
            }
        }
    }//sieve_end
    int prime[n];//storing all primes in prime[].
    int j=0;
    for(i=2;i<n;i++)
    {
        if(A[i]!=0)
        {
            prime[j++]=i;

        } 
    }
    int a,b,count[10001];
    for(i=0;i<10001;i++)
        count[i]=0;
    for(a=0; a<j; a++)//j=number_of_primes
    {    
        for(b=0;b<j;b++)
        {
            if(prime[a]+2*prime[b]<=10000)
                count[prime[a]+2*prime[b]]++;
        }
    }
    printf("%d\n",count[n]);
}


return 0;

}

asked 22 Jun '14, 23:17

j1k7_7's gravatar image

5★j1k7_7
01
accept rate: 0%


Done..:D

link

answered 23 Jun '14, 02:04

j1k7_7's gravatar image

5★j1k7_7
01
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×3,741
×1,477
×301

question asked: 22 Jun '14, 23:17

question was seen: 989 times

last updated: 23 Jun '14, 02:04