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, 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.

Example

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5
Warning: 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
nananaw1: 2019-06-23 23:22:37

hate how i compile my code on my ide and it works but always getting error for this site
bs

saurav_03: 2019-06-18 22:00:20

good problem for understanding segmented sieve.

stocke777: 2019-06-18 20:23:48

horrible site, cant submit shit, no program ever seems to work, total time waste

<snip> no code

Last edit: 2022-06-19 12:08:37
pbhadu21: 2019-06-18 10:13:21

@kiroma thanks dude, it really saved me ! :):)

aman_sai18: 2019-06-17 21:01:54

How to do it python without getting run-time error

yvanjaquino: 2019-06-10 22:32:30

Anyone tried this in python? How do you accept the input?

emir_mirbekov: 2019-06-02 19:07:57

This exercise making me really mad because it says that I have tml but in ideone it takes 0.01seconds to execute and compile. In my opinion this problem is a bit wrong maybe its test case having problems.

pyskmr: 2019-05-29 20:36:24

to check a prime number say x
simply check from i =2 to i<=sqrt(x)
you would never get TLE
no need to use fancy data structures and all.

THAT'S WHY THIS QUESTION IS UNDER NUMBER THEORY,BECAUSE CHECKING A NUMBER PRIME TILL ITS SQUARE ROOT IS A NUMBER THEORY CONCEPT OR DISCRETE MATHS CONCEPT

Last edit: 2019-05-29 20:38:33
saurav_paul: 2019-05-26 09:00:13

AC in one go .
I used segmented sieve....

saurav_paul: 2019-05-26 08:59:17

vortex733, you can use segmented sieve, it will save you from time limits exist;


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