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
king: 2015-10-24 12:01:50

Finally ac after 4 WA :)
use seive with an array of 100000 with slight change

sonali9696: 2015-10-20 09:53:24

Okay this is the limit..! Ideone says "Success" but spoj says "Wrong Answer". Spoj really tests people's patience!!

Last edit: 2015-10-20 09:54:04
felipvilar2: 2015-10-19 20:26:09

to save time, just check until sqrt(n)... solved my runtime error

maddy_7: 2015-10-19 16:24:27

my code is running on ideone very well, and here run time error .. kindly help asap ..
<snip>
ideone link !!

Last edit: 2022-06-19 12:19:46
stanzinkdl: 2015-10-19 11:20:26

my submission shows exceeded time limit how can i optimse time

billyfournier: 2015-10-16 23:03:48

I'm doing this in c. I believe my outputs are correct, but my submission says I have the wrong answer. Can the form of my input cause an incorrect answer?

Last edit: 2015-10-16 23:04:02
cqui: 2015-10-16 17:15:06

6s time limit, my poor little code need 11 time this, on my machine, back on the drawing board, :(

kartik0007: 2015-10-13 10:25:31

Before submission make sure to test this test case :
1
999900000 1000000000

Last edit: 2015-10-13 10:25:59
doanva: 2015-10-13 10:17:06

Use this checking method would be accepted
bool isPrime(int i) {
...
}

Last edit: 2015-10-13 10:17:51
Abhimanyu Srivastava: 2015-10-12 18:24:46

sieve of erasthonesis doesn't work


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