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
2015-07-19 23:31:31
I'm getting wrong answer although the code runs fine against a pre-computed list...
2015-07-13 12:54:41
easy
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
2015-07-08 07:59:23
got AC in C.. without using sieve of eratosthenes.. though it takes 3.68s :)
2015-07-06 21:51:47 Gowtham.R
Finally AC 0.01 !!
2015-07-05 18:36:25 vimal prajapati
i got compilation eror... i think i didnot subbmited correctly...please help me.. hoe to subbmit java code.
2015-07-04 13:21:09
Should I use the normal method of exclusion or should I prefer sieve of Eratosthenes for this?
2015-07-04 12:41:18
I got a "time limit exceeded", what is that mean ?


Last edit: 2015-07-04 12:42:37
2015-07-04 12:26:34 Varun
used sieve of eratosthenes. repeatedly getting wrong answer from spoj although working fine on ideone.


Last edit: 2015-07-04 12:27:54
2015-06-28 21:11:50
Why I get everytime a timeout error?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.