結果

問題 No.1350 2019-6problem
ユーザー sten_sansten_san
提出日時 2021-01-24 20:08:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 192,072 KB
最終ジャッジ日時 2025-01-18 07:58:23
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

int main() {
    int64_t a, b, k; cin >> a >> b >> k;
    auto c = lcm(a, b);

    auto rank = [&](auto n) {
        return n / a + n / b - n / c;
    };

    int64_t left = 1, right = 1000000000000000001ll;
    while (1 < right - left) {
        auto mid = left + (right - left) / 2;
        if (rank(mid) <= k) {
            left = mid;
        }
        else {
            right = mid;
        }
    }

    cout << max(left / a * a, left / b * b) << endl;
}

0