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-10-31 17:14:40 Gaurav Agarwal
im new to C programming, could someone tell me whats wrong with this program ----> http://ideone.com/e.js/8VOifP

Last edit: 2014-10-31 17:15:13
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 Soccer Star
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
2014-08-16 20:58:59 Sachin Gautam
solved without using [removed] :P

Last edit: 2014-10-29 05:48:21
2014-07-20 16:00:01 [Lakshman]
@Aragon!!! Your algorithm is wrong. Do you know how to check a number is prime or not. And your assumption that if number is not divisible by 3,5,7 is prime is wrong.

Last edit: 2014-07-20 16:01:27
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.