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

Time limit exit!
Posted by Ayaz 13 Aug 2017 12:47
I have used sieve theorem but i am still getting TLE! i need my code optimization .here is my code:

#include<iostream>
#include<cmath>
using namespace std;
#define TOTAL 163841
int main()
{

 int ara[TOTAL];

    for(int i=2; i<TOTAL; i++)
    {
        ara[i]=1;

    }
     int root = sqrt(TOTAL);

    for(int i=2; i<=root;i++)
    {
        for(int j=2; i*j<=TOTAL; j++) \\ Using  sieve theorem
        {
            ara[i*j]=0;
        }
    }
int T;
 int n;
cin >> T;
int r,k;
for(int l=1; l<=T; l++)
{

cin >> n;

if(n<=15000)
{
int ara2[n];
for(k=2,r=1;r<=n;k++)
{
    if(ara[k]==1)
    {
        ara2[r]=k; \\ copying the prime numbers to the ara2[]
        r++;
    }

}

cout << ara2[n] << "\n"; // cout the last num of ara2[]

}
}
return 0;
}

Edited by author 13.08.2017 12:49