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

For those dude who thinks sieve is only option
Posted by Shomik Shahriar 11 May 2025 11:57
DO your own solve then check this do not cheat yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define FastAF ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

template <typename T> // cin >> vector<T>
istream &operator>>(istream &istream, vector<T> &v){for (auto &it : v) cin >> it;return istream;}
template <typename T> // cout << vector<T>
ostream &operator<<(ostream &ostream, const vector<T> &c){for (auto &it : c) cout << it << " ";return ostream;}

const int mx=2e5;

int ar[mx];
void d(){
    ar[0]=2;
    int k=1;
    for(int i=3;i<mx;i++){
        bool f=true;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f){
            ar[k++]=i;
        }
    }
}

int main(){
    FastAF
    d();
    int n;
    cin>>n;
    while(n--){
        int a;cin>>a;
        cout<<ar[--a]<<endl;
    }
return 0;
}

Algo: sqrt with precomputation

Edited by author 11.05.2025 11:58

Edited by author 11.05.2025 12:02