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!


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.


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.


1 10
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
Time limit:6s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-11-10 18:32:34 Raghib
can someone tell me what's wrong with this. why is the time limit exceeding?

--edit(Francky)-->[code removed] ; Read the notes below : no code here ; please.

Last edit: 2014-11-10 21:08:54
2014-11-10 10:52:02 John Manuel T. Bernardo
Please check my code. I'm not sure with the display that's why I'm always getting a wrong answer.
2014-11-05 22:06:30 Jasdeep Singh
when i do using a normal algo it works
but in seive of erastosthenes it tle can someone explain me this
2014-10-28 12:39:29 `Ak
Is the time limit been extended as code are being submitted easily on it ??

[reply by cyclops: The cluster got changed from Pyramid to Cube for some reason. It happened to several problems and with some negative effects. I wrote to admins about it but haven't heard a reply yet.]

Last edit: 2014-10-29 05:38:23
2014-10-26 03:00:12 appy
this question can only be done by
[hint removed by cyclops]
(google it)

--ans(Francky)--> The "only" is false in your sentence, it should be "for example", ...

Last edit: 2014-10-29 05:48:33
2014-10-22 11:10:10 Daniel Cárdenas
Solved it on python. Finally.
2014-10-12 18:30:50 Mitch Schwartz
@Paradigm Shift: The standard judge on SPOJ ignores extra whitespace. Only in rare cases is a different judge used, and most of the time there is a note about it in the problem statement or a comment about it.
2014-10-12 17:35:29 The Lazy Programmer
What to print when there is no prime: an empty line corresponding to it or just ignore that test case ?

Last edit: 2014-10-29 05:41:02
2014-09-25 13:13:32 Yash Bansal
This is my code. Why i am getting it as wrong answer even it is working fine on my pc compiler?
Please help.
[code removed by cyclops -- see notes at bottom, "1. Don't post any source code here." You may be interested in the forum; be sure to read TripleM's "Read this before posting!" and Leppy's "PLEASE USE CODE TAGS" before posting.]

Last edit: 2014-09-25 16:52:03
2014-09-21 01:06:16 Craig
For those with "it works on ideone.come, but TLEs here", please note : "Intel Pentium III 733 MHz". You need to code to that limitation. Likewise for "256MB"

Last edit: 2014-09-21 01:07:15
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.