結果

問題 No.2066 Simple Math !
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2022-09-04 12:15:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,208 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 76,464 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-29 11:43:04
合計ジャッジ時間 7,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 263 ms
5,376 KB
testcase_05 AC 263 ms
5,376 KB
testcase_06 AC 262 ms
5,376 KB
testcase_07 AC 263 ms
5,376 KB
testcase_08 AC 263 ms
5,376 KB
testcase_09 AC 263 ms
5,376 KB
testcase_10 AC 263 ms
5,376 KB
testcase_11 AC 263 ms
5,376 KB
testcase_12 AC 263 ms
5,376 KB
testcase_13 AC 270 ms
5,376 KB
testcase_14 AC 255 ms
5,376 KB
testcase_15 AC 257 ms
5,376 KB
testcase_16 AC 257 ms
5,376 KB
testcase_17 AC 258 ms
5,376 KB
testcase_18 AC 259 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 179 ms
5,376 KB
testcase_25 AC 178 ms
5,376 KB
testcase_26 AC 178 ms
5,376 KB
testcase_27 AC 178 ms
5,376 KB
testcase_28 AC 181 ms
5,376 KB
testcase_29 AC 52 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dump(x) cout << #x << " = " << (x) << endl;

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

template<class T>
T floor_sum(T n, T m, T a, T b) { //sigma(i=0~n-1){[(ai+b)/m]}
    T res = 0;
    res += (a / m) * n * (n - 1) / 2;
    res += (b / m) * n;
    a = a % m;
    b = b % m;
    T ymax = a * n + b;
    if (ymax < m) return res;
    res += floor_sum(ymax / m, a, m, ymax % m);
    return res;
}

int main()
{
    int t;
    cin >> t;
    while (t--) {
        ll p, q, k;
        cin >> p >> q >> k;
        ll ok = 0, ng = min(p, q) * k + 1;
        while (ng - ok > 1) {
            ll mid = (ok + ng) / 2;
            ll cnt = mid / q;
            ll n = mid / q + 1;
            ll m = p;
            ll a = q;
            ll b = mid % q;
            cnt += floor_sum<ll>(n, m, a, b);
            if (cnt < k) ok = mid;
            else ng = mid;
        }
        cout << ng << endl;
    }
    return 0;
}
0