結果

問題 No.2066 Simple Math !
ユーザー t98slidert98slider
提出日時 2022-09-04 20:46:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 4,043 ms
コンパイル使用メモリ 137,900 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-12 05:56:28
合計ジャッジ時間 10,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 63 ms
4,384 KB
testcase_02 AC 74 ms
4,380 KB
testcase_03 AC 23 ms
4,384 KB
testcase_04 AC 217 ms
4,380 KB
testcase_05 AC 212 ms
4,376 KB
testcase_06 AC 205 ms
4,376 KB
testcase_07 AC 213 ms
4,376 KB
testcase_08 AC 211 ms
4,380 KB
testcase_09 AC 212 ms
4,376 KB
testcase_10 AC 214 ms
4,388 KB
testcase_11 AC 208 ms
4,376 KB
testcase_12 AC 212 ms
4,380 KB
testcase_13 AC 216 ms
4,380 KB
testcase_14 AC 194 ms
4,376 KB
testcase_15 AC 192 ms
4,376 KB
testcase_16 AC 187 ms
4,380 KB
testcase_17 AC 187 ms
4,380 KB
testcase_18 AC 195 ms
4,380 KB
testcase_19 AC 130 ms
4,380 KB
testcase_20 AC 128 ms
4,376 KB
testcase_21 AC 131 ms
4,380 KB
testcase_22 AC 132 ms
4,376 KB
testcase_23 AC 132 ms
4,380 KB
testcase_24 AC 185 ms
4,380 KB
testcase_25 AC 189 ms
4,380 KB
testcase_26 AC 189 ms
4,380 KB
testcase_27 AC 192 ms
4,380 KB
testcase_28 AC 188 ms
4,380 KB
testcase_29 AC 58 ms
4,380 KB
testcase_30 AC 27 ms
4,380 KB
testcase_31 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/all>
using namespace std;
using ll = long long;

int main(){
    int t;
    cin >> t;
    while(t--){
        ll p, q, k, g;
        cin >> p >> q >> k;
        g = __gcd(p, q);
        p /= g, q /= g;
        if(p == 1 || q == 1){
            cout << g * k << '\n';
            continue;
        }
        auto f = [&](ll v){
            ll r = min(q, v / p + 1);
            return atcoder::floor_sum(r, q, p, v + q - p * (r - 1));
        };
        ll ng = 0, ok = 1ll << 60, mid;
        while(ng + 1 < ok){
            mid = (ng + ok) / 2;
            if(f(mid) <= k)ng = mid;
            else ok = mid;
        }
        cout << g * ok << '\n';
    }
}
0