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!


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.


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.


1 10
3 5


Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)


After cluster change, please consider PRINT as a more challenging problem.

hide comments
ani1107: 2018-08-24 21:45:13

Guys this is not a fair problem of checking the optimal solution!!

sg99a: 2018-08-23 16:37:11

Last edit: 2018-08-23 16:37:35
kaustuvsahu: 2018-08-19 17:19:41

even with sieve if i use cout for output time limit exceeded

sam_abhi: 2018-08-17 10:53:28

guys always check for 1. it should not suppose to be printed and use square n method

div_25: 2018-08-12 20:17:00

Guys check for 1. I spent a ton of time only to find 1 was showing up as prime. And use sqrt().

magnus_007: 2018-08-06 12:15:23

use normal method no need to use sieve or segmented

badtmeez: 2018-08-03 06:58:42

Use segmented sieve.......

chirag74: 2018-08-02 23:03:52

LOL guys i was literally scratching my head trying to apply sieve of erastothenes to find all primes upto billion and some other algorithm. Trust me it wont work cus they dont even test it upto a billion. Just check if the number is a prime each time. LOLOLOL. Man i hate this question. I really wonder why is it in classical?

paresh121: 2018-08-01 16:34:14

how to reduce time to print a number?
when i did'nt used print command code done processing to about 3000 numbers in .038sec but using print it takes 4.78 sec what to do?

division_7: 2018-08-01 16:03:48

This Question is amazing as if it has no answer to it i tried using python,c and cpp even that sieve algo none works only TLE error is there my god.

Added by:Adam Dzedzej
Time limit:6s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6