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-06-29 21:01:41 Madhusudhan K
My code ran in 0.01 sec on ideone.com http://ideone.com/vYN4MI

But on spoj, it says "time limit exceeded". Can someone help me optimise this code? thanks!

Last edit: 2013-06-29 21:05:38
2013-06-25 08:16:30 Shivam Dimri
is the source cluster slow??
coz i am always getting time limit exceeded problem??
2013-06-24 09:37:28 Artem
Почему у меня не засчитывается здесь задание? Тут всё работает: <snip>

Last edit: 2022-06-19 12:29:16
2013-06-20 13:43:01 Himanshu
@neo thanx but tell me how to optimize my solution......my code is running in 2.81sec
2013-06-09 21:48:41 László Tamás
Ok, so can someone tell me, whether this program waits for the input from console or not? Seems everything is fine but i always get Wrong Answer.
2013-06-01 00:15:11 Chandan Mittal
finally the sieve passed :)

Last edit: 2013-07-05 08:03:23
2013-05-25 18:15:12 drazen167
@Jaideep
their processor is PENTIUM III (not so fast as today's PCs)

Last edit: 2013-05-25 20:08:45
2013-05-25 18:14:41 drazen167
I think my code is right and fast.
Please can anyone tell the mistake in it.
giving WA
<snip>

Last edit: 2022-06-19 12:29:31
2013-05-24 08:50:26 amitsingh749
time limit exceed why ....
in my system it is working fine with in sec
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.