結果

問題 No.897 compαctree
ユーザー noisy_noimin
提出日時 2019-10-04 21:28:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 166,372 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-03 07:11:47
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll solve(ll n, ll k) {
    if(k == 1) return n-1;
    if(n == 1) return 0;
    ll ng = 0, ok = n;
    while(ok - ng > 1LL) {
        ll mid = (ok + ng) / 2;
        if((pow(k, mid) - 1) / (k-1) >= n) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok-1;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int Q;
    cin >> Q;
    ll n, k;
    while(Q--) {
        cin >> n >> k;
        cout << solve(n, k) << endl;
    }
}
0