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
2013-03-24 08:11:54 Sushant Mahajan
@Prabodh, time limit will exceed. This is not the way to handle this problem. Look into Sieve of Eratosthenes algo. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
2013-03-23 17:30:32 Harkrishn Patro
please help me someone mine time limit is getting exceeded
2013-03-22 22:13:17 Anudeep Samaiya
I have submitted the successful solution of this problem but no points are awarded...what should I do ?
2013-03-19 17:09:43 sunidhi
why it is showing runtime error
2013-03-15 19:26:09 Alex
Is it possible to fix the setup? Compiler of "stone age" doesn't understand int64_t and doesn't handle "long long" properly as well....
while compiling:
-----------------------------------
static bool isPrime(long long n) {}
-----------------------------------

compilation error like printed below is strange....
prog.cpp: In static member function 'static bool SPOJ::prime::isPrime(long long int)':
prog.cpp:44: error: expected primary-expression before 'long'
prog.cpp:44: error: expected ',' or ';' before 'long'

PS. Really interesting: compilation error gone when making isPrime template function....

Last edit: 2013-03-15 19:58:18
2013-03-13 22:12:29 skard
maximum limit is 10^9.
2013-03-13 22:12:29 Santosh
What the hell? I guess the maximum limit of m,n is 10^10 instead of 10^9. My codes work only if I assume the maximum limit to be 10^10 !!
2013-03-13 22:12:29 himanshu tyagi
sir in my computer time limit is satisfied
but here not why?
2013-03-13 22:12:29 himanshu tyagi
sir how can i reduce my time limit
2013-03-13 22:12:29 pbd
<snip>
what is wrong

Last edit: 2023-05-27 18:26:53
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.