ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1086. Криптография

For those dude who thinks sieve is only option
Послано Shomik Shahriar 11 май 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