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
2014-06-29 16:37:36 TechIcon01
I have written code for this in java and by using seive of erastosthenes method for finding primes number.It is running absolutely perfect in my machine.But spoj says its wrong answer ..i have tested by giving big numbers and with 6 testcases as well..any clue?

Last edit: 2014-06-29 16:38:09
2014-06-27 08:41:17 [Lakshman]
@code_do RTE because of too much memory allocation at run time, max n can be 10^9 and you can allocate this much of memory, Try to learn segmented sieve.
2014-06-27 08:06:51 code_do
@Adam I am getting SIGABRT error in my code,but its running fine on ideone.please help me with this
<snip>

Last edit: 2022-06-19 12:36:49
2014-06-26 22:04:41 Poonam Adhav
my code runs fine on ideone.com but gives time limit exceeds....please help
2014-06-25 16:24:13 kotti satish
i've tried many test cases.....still time limit exceeds
2014-06-25 13:35:47 Yosra
I got compilation error. Can any one help me to catch what's wrong?
2014-06-23 10:12:15 Archit Jain
good one...!!
2014-06-21 19:22:13 Adarsh K
Can anyone give the capacity of given system?? The no of operations it can perform in one second?? Also pls give me the maximum size of an array supported by the compiler...

Last edit: 2014-06-21 19:24:26
2014-06-20 20:13:02 kishon
I too keep getting runtime error (SIGSEGV) :-(
2014-06-17 19:24:20 classified_01
Optimized sieve not helping either.....runtime error (SIGSEGV) .
How can i overcome the error ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.