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.

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

hide comments
2015-11-04 17:31:54 Shidhu
please help someone. i am getting runtime error. but why ?
2015-11-04 17:29:59 Shidhu
why i am getting runtime error ??
2015-11-01 16:38:54 HEMANTH SAVASERE
nice problem
opportunity to appreciate Eratosthenes who made this algorithm nearly 2000 years ago
Great!!
2015-11-01 11:32:51
how to read the lines in python....i am using input() but it says EOF while reading a line
2015-10-31 20:40:12
Use Math.sqrt(k)+1 for getting speed.
2015-10-27 14:15:23
HEY !!! MR. ANKIT KUMAR, PLEASE DONT PUT SOLUTION IN COMMENT
2015-10-26 16:16:53
Nice problem just remember p(n) can be written as 6k +- 1 and try to keep complexity between M*N^(1/2).

Last edit: 2015-10-26 16:20:16
2015-10-26 12:29:58
how can I know how much time is needed for running my code?
2015-10-24 13:16:14
time limit exceeded!! Help!!
2015-10-24 12:01:50 king
Finally ac after 4 WA :)
use seive with an array of 100000 with slight change
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.