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
Mateusz: 2013-08-21 21:57:49

yhm... I implemented solution in Ruby and it passes all test cases which I created however it shows Wrong Answer when I submit it to SPOJ. here is code and some tests on ideone: <snip> If someone could suggest what could be wrong.

Last edit: 2022-06-19 12:32:37
Kishlay Raj: 2013-08-13 14:35:32

vids u dont need to use sqrt u can simply campare it like i*i<n instead of i<sqrt(n)

do_do: 2013-08-11 07:04:28

what is time limit exceeded?plz help

Sushil: 2013-08-09 22:18:58

getting NZEC error using java ..help or any hints

John and the cows: 2013-08-08 12:21:06

AC at first attempt :)

Last edit: 2013-08-08 13:55:18
Kishlay Raj: 2013-08-07 19:06:59

i hav used sieve but it giving worng and can any1 give me a good test case to check with

Bohdan Taraba: 2013-08-07 16:26:36

i think i have some problem with input or output. My algorithm is working fine but i have still wrong answer. Which way is correct implementation of input in C/C++ ?

AMIT KUMAR MAURYA: 2013-08-02 11:49:48

got the answer!!! thumbs up

ROHIT KUMAR: 2013-08-01 17:45:56

its done aftr 2 months...
nice prob :)

vids: 2013-08-01 09:46:21

I am getting compilation error bcoz of sqrt(n), and header file, 'math'. what is the header file for sqrt, in c++.


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