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
luisdanielmesa: 2015-07-19 23:31:31

I'm getting wrong answer although the code runs fine against a pre-computed list...

mzy115: 2015-07-13 12:54:41

easy

pawan_gupta: 2015-07-10 16:10:23

its shows correct output but for a large number gives runtime errror on ideone.
Also its gives correct output on my compiler .
can anyone help what may be the problem?

Last edit: 2015-07-10 16:16:05
ashish22_dwd: 2015-07-08 07:59:23

got AC in C.. without using sieve of eratosthenes.. though it takes 3.68s :)

Gowtham.R: 2015-07-06 21:51:47

Finally AC 0.01 !!

vimal prajapati: 2015-07-05 18:36:25

i got compilation eror... i think i didnot subbmited correctly...please help me.. hoe to subbmit java code.

bansalsushant: 2015-07-04 13:21:09

Should I use the normal method of exclusion or should I prefer sieve of Eratosthenes for this?

minhquan1201: 2015-07-04 12:41:18

I got a "time limit exceeded", what is that mean ?

Last edit: 2015-07-04 12:42:37
Varun: 2015-07-04 12:26:34

used sieve of eratosthenes. repeatedly getting wrong answer from spoj although working fine on ideone.

Last edit: 2015-07-04 12:27:54
knabmn: 2015-06-28 21:11:50

Why I get everytime a timeout error?


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