結果

問題 No.1651 Removing Cards
ユーザー nawawan
提出日時 2021-08-20 22:47:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 196,512 KB
最終ジャッジ日時 2025-01-24 00:06:34
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int K, Q;
    cin >> K >> Q;
    vector<long long> ans;
    ans.push_back(K);
    while(ans.back() <= 1000000000000000000){
        long long temp = ans.back();
        long long ub = 100000000000000;
        long long lb = -1;
        while(ub - lb > 1){
            long long mid = (ub + lb) / 2;
            long long t = mid * (K - 1);
            if(t < temp) lb = mid;
            else ub = mid;
        }
        ans.push_back(ub + temp);
    }
    while(Q--){
        long long N;
        cin >> N;
        if(N <= K) cout << N << endl;
        else{
            int ind = lower_bound(ans.begin(), ans.end(), N) - ans.begin();
            cout << ans[ind - 1] << endl;
        }
    }
}
0