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
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
drazen167: 2013-05-25 18:14:41

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
amitsingh749: 2013-05-24 08:50:26

time limit exceed why ....
in my system it is working fine with in sec

coding: 2013-05-20 06:56:48

phewww!!! after so many tle..jst because i was taking numbers upto n/2...got AC when taking sqrt(n) :P :D


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