#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main() {
  unsigned long n,i,j,tof,ii;
  bool test;
  vector<unsigned long> a;
  cin >> n;
  a.resize(n);
  a[0] = 2;
  ii = 1;
  for(i = 3; ii < n; i+=2) {
    tof = sqrt(i);
    test = true;
    for(j = 0; a[j] <= tof; j++)
      if (i % a[j] == 0)
        test = false;
    if (test) {
      a[ii] = i;
      ii++;
    }
  }
  cout << a[a.size() - 1] << endl;
}

Add a code snippet to your website: www.paste.org