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
shubham_chopra: 2018-01-19 20:29:38

use segmented sieve, normal sieve will give TLE

suchismitadhal: 2018-01-19 15:41:20

for TLE no need of Sieve algo., filter the numbers against 2 to the square root of the number. Accepted.

hsakiv220290: 2018-01-17 12:17:05

@manahax, 1 is divisible by 1 and itself. SO it is prime

youngchaeseo: 2018-01-17 08:21:48

I tested the problem and worked, but the real problem question doesn't work. hmmm

manahax: 2018-01-16 22:08:24

@hsakiv220290, 1 is not prime

nayan_ansh: 2018-01-14 07:53:39

I am using java and my code work in my computer(outside this website) but it is showing error when I submit it.

vikramvarun: 2018-01-11 13:51:24

Solved in java but getting WA in R. ID 20965189 and 20965178 (tried both with and without empty line at end of last test case). Sample test case prints expected output and I can't find any problem. Please help.

hsakiv220290: 2018-01-10 08:35:52

In example, 1st test case ,1 is a prime number.

vuminhthanh01: 2018-01-03 15:34:27

Last edit: 2018-01-03 15:34:46
vuminhthanh01: 2018-01-03 15:34:22

It doesn't work when I use python 3, then I AC with C++ in 1.5s :v

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