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
masho: 2015-10-01 17:53:01

Code ststus is "success" in idone.com but SPOJ environment showing error. why? Any suggestion?

dungen_master: 2015-09-30 15:42:54

time limit exceeded!!
any suggestions?

ash_king_1: 2015-09-30 08:56:55

time limit exceeded help

umakanth10: 2015-09-22 17:00:46

Segmented SIeve, you get a green tick :)

armagan: 2015-09-20 17:28:24

can anyone help me with the prime generator program

gj_21: 2015-09-20 14:59:47

well i'm getting segmentation fault someone help me out here please !

deep2349: 2015-09-19 21:29:47

my prog is running in c but its giving runtime error?
whats wrong with it?

Last edit: 2015-09-19 21:32:50
carofe82: 2015-09-17 15:57:21

My solution in Python gets a TLE, but the same solution in java runs in 2.3s. You don't need Sieve to get your Java solution AC. And I just tested it with PYPY and I got AC in 1.01s. So I think it is the CPython 3 the one getting TLE.

Last edit: 2015-10-07 15:36:29
xceptor: 2015-09-12 12:15:12

weak Test Case.

alexzandros: 2015-09-11 04:09:19

0.43 secs after lots of tries. Very happy I made it. Python 3.4. Erathostenes and a little bit shifting did the trick

Last edit: 2015-09-11 04:10:23

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