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

Why Runtime error(access violation)
Posted by Iqramul Islam 29 Oct 2018 23:46
#include <iostream>
#include <math.h>
using namespace std;

int Prime[15000], nPrime;
int mark[15000];

void sieve(int n)
{
    int i, j, limit=sqrt(15000)+2;

    mark[1]=1;  ///mark is not prime...so...

    for(i=4; i<=n; i+=2)
        mark[i]=1;

    Prime[nPrime++]=2;

    for(i=3; i<=n; i+=2)
        if(!mark[i])
        {
            Prime[nPrime++]=i;
            if(i<=limit)
            {
                for(j=i*i; j<=n; j+=i*2)
                    mark[j]=1;
            }
        }
}

int main()
{
    sieve(15000);
    int n;
    cin >> n;
    int arr[2000];
    //cout << Prime[n-1] << endl;

    for(int i=0; i<n; i++)
        {
            cin >> arr[i];
        }
    for(int i=0; i<n; i++)
        cout << Prime[arr[i]-1] << endl;

        return 0;
}