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
Languages:All except: CLOJ F# PERL 6 TECS

hide comments
2010-06-15 12:29:10 here for optimisation


Last edit: 2010-06-15 12:30:36
2010-06-06 18:58:15 Jargon
@jgomo3
Many psetters will submit solutions by other people with modifications to see if they can solve a bug in the code. (I know I do.) This results in some non-accepted answers by psetters.
2010-06-06 18:11:32 Jesús Gómez
What a Joke. kfas got wrong answer. http://www.spoj.pl/status/PRIME1,kfas/
:D
2010-06-06 11:03:51 Mayank Singh
yipppeee!!! problem solved... never thought such a small change to code could change execution time by 10 secs.
2010-06-01 05:04:42 adnan chowdhury
this program works fine on my ubuntu machine, but I get SIGSEV on here...

i'm not even sieving for each test case, i only sieve once and store a list of primes for reference!
2010-05-29 01:25:34 Amir Hossein Shahrairi
@suji: getch() function is not standard (new compilers don't accept it)
remove it from your code and then submit again
2010-05-27 08:28:11 suji
its working in my laptop but i get error for getch(); should have a prototype wat shud i do
2010-05-26 20:17:44 Janis Gruzis
Solved. :)

Last edit: 2010-05-26 20:19:06
2010-05-25 09:06:23 aleemullah khan
guys i dont know y i get time limit exceeded although it doesn't take more then a second to run...
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.