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-09-01 13:57:40 Siddharth Bhal
Why segmentation fault on spoj. <snip>
Its working good on idone and on my system also!
Please help

Last edit: 2022-06-19 12:30:23
2013-08-31 05:37:50 ANURAG DAS
guys,i have tried sieve of eratosthenes for prime generation,yet time limit is crossed.
help me..
2013-08-30 04:42:19 Pablo Fuente
I donĀ“t know how to output test cases with no primes in the range. So, What should be the output for this input a,b or c?
Another thing, the output could end with more than one new line after the last prime?

Input
2
1 10
4 4
3 5

Output a
2
3
5
7

3
5

Output b
2
3
5
7


3
5

Output b
2
3
5
7



3
5

Last edit: 2013-08-30 04:50:36
2013-08-28 04:33:09 Rohit pal
time limit exceeded f**k this
2013-08-24 12:08:14 Moudud
my code run and give right output in my pc but got RTE :(
2013-08-23 09:49:16 sazzad hossain
what is compilatin error?plz help
2013-08-22 20:04:19 Sherfudeen Mohamed Kasim
My java code working fine but it's timed out. I might need to change the code to write into stringbuffer to print on console at one shot.

But I welcome any suggestion.

Thanks
2013-08-22 08:31:48 Mateusz
I believe I have some problems with input and output, as my solution passes all tests which I can only imagine on ideone... <snip>

Last edit: 2022-06-19 12:30:40
2013-08-22 02:19:47 Andrey K
haha
I have realized, to solve this quickly, you have to avoid O(n^2)
Just make sure you avoid same calculations twice :-D
2013-08-21 21:57:49 Mateusz
yhm... I implemented solution in Ruby and it passes all test cases which I created however it shows Wrong Answer when I submit it to SPOJ. here is code and some tests on ideone: <snip> If someone could suggest what could be wrong.

Last edit: 2022-06-19 12:32:37
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.