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 WA#2
Posted by MrFazer 4 Jan 2024 23:25
#include "bits/stdc++.h"

#define int long long
using namespace std;

vector<int> eratosfen() {
    int n = 168841;
    vector<bool> res(n + 1, false);
    for (int i = 2; i <= n; ++i) {
        if (!res[i]) {
            for (int j = i * i; j < n; j += i) {
                res[j] = true;
            }
        }
    }
    vector<int> res2;
    for (int i = 2; i < res.size(); ++i) {
        if (!res[i]) {
            res2.push_back(i);
        }
    }
    return res2;
}

signed main() {
    int t;
    cin >> t;
    vector<int> a = eratosfen();
    while (t--) {
        int n;
        cin >> n;
        if (n == 1) {
            cout << 2;
            continue;
        }
        cout << a[n - 1] << endl;
    }
}
Re: WHY WA#2
Posted by Solfind 5 Jan 2024 12:00
you should count the eratosphen for a larger n in your function