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
2013-11-26 13:08:14 luke manuel daely
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.
2013-11-20 21:13:17 numerix
@Risto: SPOJ servers are slow. Optimize your approach.
2013-11-20 20:31:24 Risto
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?
2013-11-16 21:02:34 LeppyR64
To those of you getting TLE. Think about what the hardest possible test case is.
2013-11-05 20:45:11 Ryaan Dias
I am getting time limit exceeded but the code run very fast in ideone => http://ideone.com/4obog0
2013-11-02 18:37:41 Ashwini
my program runs successfully in ideone in 5 secs here judge is giving me tle:( <snip>

Last edit: 2022-06-19 12:31:33
2013-11-01 11:50:08 Navaneeth R
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
2013-10-25 14:10:13 amit
my code runs properly on ideone,but online judge shows run time exceeded.Please help...<snip>

Last edit: 2022-06-19 12:31:18
2013-10-24 22:38:33 Mohammed Hafez
@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 :)
2013-10-24 01:26:41 code_new
Always time limit exceeded
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.