Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

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: PERL 6

hide comments
2012-05-20 12:45:15 Mads
Hi when i run my program on local computer it works and generates the right results and when i test it on Ideone.com it gets the green light and generates the correct results.

But when i run it on SPOJ i get NZEC error. What is the problem?

Sorry no code because it says comment to long but the code is in JAVA.
2012-05-19 13:46:47 Ali Abdallah Awad
I Hate Time limit executed :(
2012-05-18 14:18:05 Tom
with input
2
1000 2000
100 200

i get
time: 0.02s
mem: 2860 kB

and still time limit exc. ;-(
2012-05-17 20:32:51 keshav gupta
#include <stdio.h>
#include <stdlib.h>
int main()
{
long int i,j,c,a[10][2];
int t;
scanf("%d",&t);
for(i=0;i<t;i++)
scanf("%ld %ld",&a[i][1],&a[i][2]);
char *sieve =(char *)calloc(1000000001,1);
for (i=2; i*i <= 1000000000; i++)
{
if(sieve[i]==0)
{
for(j=i+i;j<1000000000;j+=i)
{
sieve[j]=1;
}
}
}
for(i=0;i<t;i++)
{
c=0;
for(j=a[i][1];j<=a[i][2];j++)
{
if(!sieve[j])
c++;
}
printf("%ld\n",c);
}
return 0;
}

can any1 hlp me it shows run tym error
2012-05-17 13:24:52 Abhishek Joshi
can somebody please tell me why the submission id 7001755 is giving a TLE I am using sieve of erastothenes.
2012-05-11 13:54:13 Thang Do
result: success time: 0.04s memory: 37984 kB returned value: 0

input:
2
1000 2000
100 200

This is what I get from Ideone.com
But I still encounter runtime error SIGKILL from SPOJ ?

Is it because I didnt specify the input for SPOJ?

Need help, please
2012-05-09 13:14:04 Andrew
I don't think this can be done in Ruby unless you just build a giant prime container and pull primes out of it instead of calculating them. Or embed C, but that's cheating, 'cuz it's no longer ruby
2012-04-13 15:14:30 Dr. Code
I think the time limit is not 6s or they are not testing n-m<=100000 and putting m=1 and n=1000000000 ..
2012-04-09 01:08:53 Diogo Soares [UFAM rulez]
@darky1 yeah! Sieve is good enough..
2012-04-08 19:28:47 darky1
Is sieve of eratosthenes good enuf?
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.