結果
問題 |
No.2526 Kth Not-divisible Number
|
ユーザー |
![]() |
提出日時 | 2023-11-08 19:21:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 346 ms / 2,000 ms |
コード長 | 949 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 41,796 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-25 23:52:36 |
合計ジャッジ時間 | 4,549 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
/* -*- coding: utf-8 -*- * * 2526.cc: No.2526 Kth Not-divisible Number - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ template <typename T> T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } template <typename T> T lcm(T m, T n) { return m * n / gcd<T>(m, n); } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int a, b; ll k; scanf("%d%d%lld", &a, &b, &k); ll l = lcm<ll>(a, b); ll r = l - l / a - l / b + 1; //printf("r=%lld\n", r); ll x0 = 0, x1 = 4000000000000000000LL; while (x0 + 1 < x1) { ll x = (x0 + x1) / 2; ll y = x % l; if (x / l * r + (y - y / a - y / b) >= k) x1 = x; else x0 = x; } printf("%lld\n", x1); } return 0; }