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-05-19 10:49:51 Love Bisaria
Time limit exceeded issue.. Not able to solve.
2014-05-14 20:17:36 pvkcse
<snip> here is my code in c# but here in spoj it is runtime error(NZEC)...can't find what the error is...!!!

Last edit: 2022-06-19 12:35:46
2014-05-13 16:30:24 Jatin Kathuria
are m and n random numbers or user input numbers?
--ans(Francky)--> n and m are fixed in a file, had been chosen by psetter.

Last edit: 2014-05-13 21:39:49
2014-05-12 23:18:37 Mislav
My segmented sieve doesn't work :S

Last edit: 2014-05-13 18:51:23
2014-05-11 19:29:18 sai spoorthy
SIR
i have done the code in java
it is running in eclipse,but when submitted it is showing compilation error
2014-05-10 11:14:19 amir elsayed
my code run on visual studio and give right answer but judge said time limit exceed why
2014-05-08 13:09:37 Michael Moerschell
@Darshak Mehta If m == n print m if it's a prime number, otherwise don't print anything
2014-04-21 19:01:55 Darshak Mehta
Can any one say me what should i print for m==n case
2014-04-11 16:56:39 Lincoln Lee
TLE T_T
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.