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
ning zhu: 2013-03-24 11:23:29

why it is showing TEL

Last edit: 2013-03-24 11:24:13
Sushant Mahajan: 2013-03-24 08:11:54

@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

Harkrishn Patro: 2013-03-23 17:30:32

please help me someone mine time limit is getting exceeded

Anudeep Samaiya: 2013-03-22 22:13:17

I have submitted the successful solution of this problem but no points are awarded...what should I do ?

sunidhi: 2013-03-19 17:09:43

why it is showing runtime error

Alex: 2013-03-15 19:26:09

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
skard: 2013-03-13 22:12:29

maximum limit is 10^9.

Santosh: 2013-03-13 22:12:29

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 !!

himanshu tyagi: 2013-03-13 22:12:29

sir in my computer time limit is satisfied
but here not why?

himanshu tyagi: 2013-03-13 22:12:29

sir how can i reduce my time limit


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