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
johnsthomason: 2015-11-04 20:18:06

Thanks!

Last edit: 2015-11-04 20:47:57
Shidhu : 2015-11-04 17:31:54

please help someone. i am getting runtime error. but why ?

Shidhu : 2015-11-04 17:29:59

why i am getting runtime error ??

HEMANTH SAVASERE: 2015-11-01 16:38:54

nice problem
opportunity to appreciate Eratosthenes who made this algorithm nearly 2000 years ago
Great!!

sudhabindu: 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

iamwgp: 2015-10-31 20:40:12

Use Math.sqrt(k)+1 for getting speed.

syukri: 2015-10-27 14:15:23

HEY !!! MR. ANKIT KUMAR, PLEASE DONT PUT SOLUTION IN COMMENT

faishal28: 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
prince_kadiwar: 2015-10-26 12:29:58

how can I know how much time is needed for running my code?

cas_blake: 2015-10-24 13:16:14

time limit exceeded!! Help!!


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