3 / 3
Mar 2020

#include
#include
#include
#include

bool checkPrime(long long N) {
long long sqrtN = sqrt(N);
if(N < 2) return false;
for(long long i = 2; i <= sqrtN; i++) {
if(N%i == 0)
return false;
}
return true;
}

int main() {
long long T;
std::cin >> T;
while(T–) {
long long start, end;
std::cin >> start >> end;
for(long long i = start; i <= end; i++) {
if(checkPrime(i) == true)
std::cout << i << std::endl;
}
std::cout << std::endl;
}
}

  • created

    Mar '20
  • last reply

    Mar '20
  • 2

    replies

  • 795

    views

  • 3

    users

  • 1

    link

there is something missing.

Try running your code on ideone.com4
There is the same engine.

Which specific error do you get - WA, TLE or NZEC?

If it’s TLE, there’s room for a little bit of optimisation in the code - how many even numbers to you need to test divide by? If that’s not enough, it takes some time to call a function.