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:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-10-02 13:27:32 mukul arora
@sanchi the normal method to find the prime won't work here
it use other algo.....!!!
me too stuck in same....google it u will find algo
2014-10-02 09:24:04 Sanchi Agarwal
int main()
int t,m,n,k,j,i,flag=0;
printf("\nenter the no. of test conditions");
printf("\nenter the range ");
scanf("%d %d",&m,&n);
if(flag==0 && j!=1)
printf("\n%d ",j);
return 0;

this is my program code. It runs perfectly fine on ideone but shows time limit exceeds on spoj. Plz someone tell me the problem.
2014-09-29 19:08:09 Raja Das
its working on ideone but its not working in spoj.its showing time limit exceeds..Whats the problem..help me..
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-22 20:07:08 Nooger
what's SIGSEGV ?

Last edit: 2014-09-22 20:52:41
2014-09-22 17:13:56 vikram sankhala
very easy one .................ac in one go......my 12th on spoj
2014-09-22 04:54:18 facug91
Sadi: maybe because your class name is PRIME1 and not Main, as it should for spoj.com in Java. Or might be because you haven't close the Scanner (sc.close())...

Last edit: 2014-09-22 04:56: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-09-20 17:42:42 diff_edge
NZEC means Non-Zero Exit Code. Which means, you forgot a "return 0" at the end.
2014-09-15 17:40:43 Giridhar Metikal

Last edit: 2014-09-15 17:42:31
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.