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
ritu: 2013-12-20 09:46:58

tle :( u have told reason of tle in previous comment but i didn't get it .. pls explain it

Pranav Zarekar: 2013-12-17 14:31:20

TLE.. :(
What care should be taken guys???

Mitch Schwartz: 2013-12-15 10:18:10

@Rohan: I deleted your latest comment for obvious reasons. conio.h is not part of standard C, so there's nothing unusual at all about that error message. http://en.wikipedia.org/wiki/Conio.h

Rohan Jitendra Pota: 2013-12-15 07:00:55

conio.h: No such file or directory
what the hell???

p@dfoot: 2013-12-12 16:57:50

my program is running perfectly on my pc but here they have not given the input correctly

Viraj: 2013-12-10 04:20:55

How do we see what tests SPOJ is running on our code?

Washington: 2013-12-05 11:10:07

lol. The author himself could not solve the problem.

Dhruv Mullick: 2013-11-30 17:08:40

Getting a SIGSEGV error in this
<snip>.. Is this because of the large array?

Last edit: 2022-06-19 12:32:06
luke manuel daely: 2013-11-26 13:08:14

for those who complain about code work very fast in ideone but get tle in spoj should try to input the maximum number of case that contain maximum number of n-m.

numerix: 2013-11-20 21:13:17

@Risto: SPOJ servers are slow. Optimize your approach.


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