ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1086. Cryptography

Getting TLE
Posted by Ahmad Jamaly Rabib 4 Nov 2018 00:06
What is the problem with my code?

#include <iostream>
using namespace std;
#include <cmath>

bool check_prime(double n) {
    int c;
    for (c=2;c<= sqrt(n);c++) {
        if((int) n%c==0)
            return 0;
    }
    if(c==(int) n)
        return 1;
}

int nth_prime(int n){
    int m=1;
    while (n>0) {
        m++;
        if (m == 2) {
            n--;
        }
        if (m%2!=0) {
            if (check_prime(m)==1) {
                n--;
            }
        }
    }
    return m;

}

int main()
{
    int n,m,i,a[15000],s;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        s = nth_prime(a[i]);
        printf("%d\n",s);
    }
    return 0;
}
Re: Getting TLE
Posted by lotus_eater 13 Nov 2018 01:46
Read about Sieve of Eratosthenes from this link :

 http://lightoj.com/article_show.php?article=1001