結果

問題 No.1651 Removing Cards
ユーザー milanis48663220
提出日時 2021-08-21 00:31:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 1,206 ms
コンパイル使用メモリ 117,976 KB
最終ジャッジ日時 2025-01-24 01:05:33
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

vector<int> as_base(int n, int k){
    vector<int> ans;
    while(n != 0) {
        ans.push_back(n%k);
        n /= k;
    }
    return ans;
}

// calc a//b 
template<typename T>
T ceil_div(T a, T b){
    return (a+b-1)/b;
}

const ll N_MAX = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int k, q; cin >> k >> q;
    auto f = [&](ll x){
        return x-(x/k+1);
    };
    auto nx = [&](ll x) -> ll{
        if(x%(k-1) == 0){
            return x+(x/(k-1))+1;
        }else{
            return x+(ceil_div<ll>(x, k-1));
        }
    };
    vector<ll> x;
    x.push_back(0);
    while(true){
        ll y = nx(x.back());
        x.push_back(y);
        if(y > N_MAX) break;
    }
    // print_vector(x);
    while(q--){
        ll n; cin >> n; n--;
        auto p = upper_bound(x.begin(), x.end(), n);
        p--;
        cout << (*p)+1 << endl;  
    }
}
0