Sphere Online Judge

SPOJ Problem Set (classical)

2. Prime Generator

Problem code: PRIME1


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)
Added by:Adam Dzedzej
Date:2004-05-01
Time limit:6s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-08-20 20:01:27 Priscilla Imandi
Im getting a time limit exceeded problem. what should i do. plz help
2014-08-16 20:58:59 Sachin Gautam
solved without using segmented sieve :P
2014-08-16 15:47:21 Swapnil Borse
can anyone kindly tell me where will I find an awesome explanation of the segmented sieve of erathosthenes???
2014-08-16 14:56:34 Swapnil Borse
@Imoen : using SIEVE of Era. won't suffice. You have to use its segmented implementation. Then the judge will accept your solution. Give it a try!!!
2014-08-15 09:06:25 Devashish Rawat
SIGSEGV Error :(
plz help
http://ideone.com/f9EGVl

Last edit: 2014-08-15 09:30:00
2014-08-10 15:04:46 Pratik Kumar
time limit exceeded please help...
http://www.spoj.com/submit/PRIME1/id=12117458
2014-08-09 21:12:57 Rajat
Segmented sieve roxxxxx
AC in one go........
awesome code
2014-08-07 16:10:45 Murat TOPAK
it's finally accepted. Segmented sieve of eratosthenes is the one you should be working on.
2014-08-03 06:29:50 zubair
http://ideone.com/IxvLp8
generates the correct o/p ...
but gives segment fault error...any1 help
2014-08-03 06:09:58 kk
finally got ac....
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.