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-06-12 13:53:44
Did anyone pass it on Python?
2015-06-12 11:13:14
@admiraldoge I have done it using Sieve, does primality test matter?
2015-06-12 05:20:44
look for PRIMALITY TEST in google an you will find the answer for you questions :)
2015-06-11 20:33:38
Wrong answer coming again and again. signal 25.
2015-06-11 15:05:21 ruler
thanks @Seven.Martinez
2015-06-11 06:31:17
getting "wrong answer" here repeatedly on submission while the answers are correct for all ranges which I have checked on ideone as well as my netbeans (I wrote it in java). What else could be the possible problems except improper printing and wrong answers ? Please help guys.
2015-06-11 04:11:24
The size of sieve array is becoming very large in worst case. What to do?
2015-06-10 20:50:09
It's my first time using SPOJ, I put my algorithm on Ideone and it says "Standard input is empty"... Do I have to put some input in my code? I left it open to the user to put the numbers... thanks
2015-06-09 22:00:18
@skywinder: don't give up! The language actually doesn't matter, it's the algorithm (and output format). How do I know? I just got "accepted" in 0.33 sec using Ruby.
2015-06-09 20:14:35
Seems it's impossible to pass it on ruby.. Go with C++ or Java, guys!

Last edit: 2015-06-09 20:16:33
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.