PRIME1  Prime Generator
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, nm<=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.
Example
Input: 2 1 10 3 5 Output: 2 3 5 7 3 5Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)
Information
After cluster change, please consider PRINT as a more challenging problem.hide comments
amit9bhasita_:
20181205 02:36:42
the approach to problem i almost same for all. you have to run a loop for n then scan l and r and further check whether num is prime or not. but the magic doesnt appear there as it relies in what condition you put in the loop to check prime. the ideal one is run a loop such that for(int k=2;k*k<NUM;K++) this is the actual magic which can take you from tle. also the real magic stays back in printing numbers for that you have to use fast io , can google it for how to use . i recommend using string builder inside all for loops and finally print. fast io can be simply found on internet Last edit: 20181205 02:42:08 

aashish_a2z:
20181128 09:06:46
You can simply run two loops one for each number from m to n and one to check whether that number is prime or not....You can run the another loop from 2 to sqrt(number) ans as u got any number which divides number then increase temp variable and use break and check if temp is greater then 1 then number is prime


neon10:
20181122 17:13:58
@thegravityguy, You got TLE because you can't generate prime number upto 10^9 using Sieve...It can generate at most 10^7 prime number using sieve...


ghastslayer29:
20181119 15:25:52
I swear to god I ran my python program in my terminal, I even tried it with very large numbers, and it runs quick, even though I have a crap top. Yet it says: 'time limit exceeded!' 

embiway1298:
20181116 17:37:17
I know the sieve of Eratosthenes method but it is showing TLE.can anyone help????


immahesh10:
20181105 16:13:10
TLE


Simes:
20181105 14:37:10
@stephentjj currently 5699 people have solved it in Java, see https://www.spoj.com/ranks/PRIME1/lang=JAVA Last edit: 20181105 14:47:34 

stephentjj:
20181105 07:30:42
Did anyone solve this in java? 

surajnobi:
20181103 06:45:39
how I take two or more inputs in single line using scanf ????? Last edit: 20181103 06:46:11 

dev_gupta01:
20181101 13:38:07
for c++ use fast I/O and segmented sieve 
Added by:  Adam Dzedzej 
Date:  20040501 
Time limit:  6s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 