Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!
Input
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
probably. how much ram do you have? You asked for
new long long int[h * sizeof(*l)];
what did you type in for h?
why are you treating new like malloc?
it looks like it should just be new long long[h] to me. That new statement looks very screwy. and long long int isnt correct, its just long long.
why do you have all the C statements and headers? <cmath> is the c++ math.h, for example.
is this using turbo C++? thats a 16(?) or 32 bit compiler, I don't think it can handle more than 2gb memory in one block.
lets stat here: does your program work if you type in 100 for h?
I don't know what your time limit is, but I was able to generate all umpteen billion primes in the entire range in 30 seconds flat with this rather idiotic approach (its pure brute force but its brute force that the computer is GOOD at). If you pre-generate that you can just peel off what is in the range for each grouping from the input.
if bt[x] is true, x is prime.
my best take at it using other methods took almost as long for just a million as this did for the whole range. you can probably tweak it even more somewhere. I don't see it, but it can't be optimal -- I didn't try to reduce the work so much as to do cheap work in bulk.
Ah. I was able to unroll it one level and it almost cut in half from 30 sec to 18. It gets ugly in a hurry but you could probably do that 3 - 5 levels deep and have the full billion in just a few seconds without even threading anything.
one level looks like
i = 2;
for(j = i*2; j < big && bt[i]; j+=i)
bt[j] = false;