This is the Link to the problem: http://www.spoj.com/problems/PRIME1/
Basically we get two limits and we have to print out all the primes between them...
Here is my Code (Language == C) :
#include <stdio.h>
void IsPrime(int test){
for(int i= 2; i<test; i++){
if(test%i==0){
return;
}
}
printf("%d\n",test);
}
int main(){
int T,lower,upper;
scanf("%d",&T);
while(T--){
scanf("%d",&lower);
scanf("%d",&upper);
for(int i = lower;i<=upper;i++){
if(i>1){
IsPrime(i);
}
}
}
return 0;
}
On my local machine I ran this and it works for the simple test cases... My message from the website is timeout error so I was wondering if there is a more efficient way to solve this problem because apparently I am not solving it fast enough?