結果

問題 No.2526 Kth Not-divisible Number
ユーザー lemondolemondo
提出日時 2023-11-03 21:37:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,902 bytes
コンパイル時間 3,393 ms
コンパイル使用メモリ 293,704 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:37:50
合計ジャッジ時間 7,074 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 271 ms
4,348 KB
testcase_04 AC 287 ms
4,348 KB
testcase_05 AC 277 ms
4,348 KB
testcase_06 AC 266 ms
4,348 KB
testcase_07 AC 263 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
#include <bits/stdc++.h>
#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long
#define OVERLOAD(e1, e2, e3, e4, NAME, ...) NAME
#define _rep1(i, n) for (long long i = 0; i < n; i++)
#define _rep2(i, a, b) for (long long i = a; i < b; ++i)
#define _rep3(i, a, b, t) \
    for (long long i = a; i * (t / abs(t)) < b * (t / abs(t)); i += t)
#define rep(...) OVERLOAD(__VA_ARGS__, _rep3, _rep2, _rep1, _)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pcnt __builtin_popcountll
#define SORT(v) sort(all(v))
#define UNIQUE(v) \
    SORT(v);      \
    v.erase(unique(v.begin(), v.end()), v.end());
#define COPY(A, B) copy(all(A), B.begin());
#define REV(v) reverse(all(v))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))

#ifdef LOCAL
#define dbg(x)                                    \
    {                                             \
        cout << __LINE__ << " : " << #x << " = "; \
        print(x);                                 \
    }

#define IS_LOCAL true
#else
#define dbg(x) true
#define IS_LOCAL false
#endif

using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T>
using vvc = vector<vc<T>>;
template <typename T>
using vvvc = vector<vvc<T>>;

template <typename T>
bool chmin(T& k, T m) {
    bool ret = k > m;
    k = min(k, m);
    return ret;
}
template <typename T>
bool chmax(T& k, T m) {
    bool ret = k < m;
    k = max(k, m);
    return ret;
}

template <typename T>
inline void print(const vector<T>& v, string s = " ") {
    for (int i = 0; i < (int)v.size(); i++)
        cout << v[i] << (i != (int)v.size() - 1 ? s : "");
    cout << "\n";
}
template <typename T, typename S>
inline void print(const pair<T, S>& p) {
    cout << p.first << " " << p.second << endl;
}
template <typename T>
inline void print(const T& x) {
    cout << x << "\n";
}
template <typename T, typename S>
inline void print(const vector<pair<T, S>>& v) {
    for (auto&& p : v) print(p);
}
void yes(bool a) { cout << (a ? "yes" : "no") << endl; }
void YES(bool a) { cout << (a ? "YES" : "NO") << endl; }
void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; }
template <typename T>
T SUM(vc<T> As) {
    T ret = 0;
    for (T a : As) ret += a;
    return ret;
}

#pragma endregion

const ll INF = numeric_limits<long long>::max() / 2;

void solve() {
    ll A, B, K;
    cin >> A >> B >> K;
    ll l = 0, r = INF;
    ll lca = A * B / gcd(A, B);
    while (l + 1 < r) {
        ll tar = (l + r) / 2;
        // tar 以下の、AでもBでも割り切れない正整数の個数
        ll cnt = tar - tar / A - tar / B + tar / lca;
        if (cnt <= K)
            l = tar;
        else
            r = tar;
    }
    print(l);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    ll T;
    cin >> T;
    rep(_, T) solve();
}
0