Can you tell me why this generates time limit exceeded in spoj(Prime Number Generator)

Posted by magiix on Stack Overflow See other posts from Stack Overflow or by magiix
Published on 2010-01-15T07:31:08Z Indexed on 2010/05/06 6:28 UTC
Read the original article Hit count: 394

#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;    

bool prime[1000000500];
void generate(long long end)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;

        for(long long i=0;i<=sqrt(end);i++)
        {
         if(prime[i]==true)
         {
             for(long long y=i*i;y<=end;y+=i)
             {
                 prime[y]=false;
             }
         }
        }
}

int main()
{
    int n;
    long long b,e;
    scanf("%d",&n);
    while(n--)
    {
        cin>>b>>e;
        generate(e);
        for(int i=b;i<e;i++)
        {
            if(prime[i])
                printf("%d\n",i);
        }
    }
    return 0;
}

That's my code for spoj prime generator.
Altought it generates the same output as another accepted code ..

© Stack Overflow or respective owner

Related posts about primes

Related posts about generator