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
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.

Risto: 2013-11-20 20:31:24

The execution time of my program is 0s, which can be seen here : http://ideone.com/NfrMUA but it says time exceeded on SPOJ. Any idea why?

LeppyR64: 2013-11-16 21:02:34

To those of you getting TLE. Think about what the hardest possible test case is.

Ryaan Dias: 2013-11-05 20:45:11

I am getting time limit exceeded but the code run very fast in ideone => http://ideone.com/4obog0

Ashwini: 2013-11-02 18:37:41

my program runs successfully in ideone in 5 secs here judge is giving me tle:( <snip>

Last edit: 2022-06-19 12:31:33
Navaneeth R: 2013-11-01 11:50:08

do we have to give a condition for the boundary conditions in our code ? (i.e for the number's range)

Last edit: 2013-11-01 11:50:28
amit: 2013-10-25 14:10:13

my code runs properly on ideone,but online judge shows run time exceeded.Please help...<snip>

Last edit: 2022-06-19 12:31:18
Mohammed Hafez: 2013-10-24 22:38:33

@Shashikant Kumar :
1. your "return 0;" is in the loop
2. try defining m, n as "long long int" not "long" only as some compilers treat "long just as "int".
Hope I helped :)


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