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-27 22:55:25 ANURAG PANDEY
TIME LIMIT EXCEEDED :(
PLEASE HELP ME OUT!!
http://ideone.com/c55cdL
2014-08-25 16:07:24 durairajaa
please some one explain me what is the input in problems (i.e file/standard input)

please explain me the procedure for submitting the problems

Last edit: 2014-08-25 16:10:42
2014-08-22 12:19:08 NAMISH SHAH GUPTA
@Devashish Rawat never use strlength() in SPOJ
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 (1307086)
Segmented sieve roxxxxx
AC in one go........
awesome code
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.