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
GuiXin: 2013-07-16 17:28:42

notice this "n (1 <= m <= n <= 1000000000, n-m<=100000)"

n may be large.
i still fail now

littlethunder: 2013-07-09 03:00:01

"time limit exceeded " !!! I cannot stand it any more!!!

Madhusudhan K: 2013-06-29 21:01:41

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
Shivam Dimri: 2013-06-25 08:16:30

is the source cluster slow??
coz i am always getting time limit exceeded problem??

Artem: 2013-06-24 09:37:28

Почему у меня не засчитывается здесь задание? Тут всё работает: <snip>

Last edit: 2022-06-19 12:29:16
Himanshu: 2013-06-20 13:43:01

@neo thanx but tell me how to optimize my solution......my code is running in 2.81sec

László Tamás: 2013-06-09 21:48:41

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.

Chandan Mittal: 2013-06-01 00:15:11

finally the sieve passed :)

Last edit: 2013-07-05 08:03:23
drazen167: 2013-05-25 18:15:12

@Jaideep
their processor is PENTIUM III (not so fast as today's PCs)

Last edit: 2013-05-25 20:08:45

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