結果
問題 |
No.2526 Kth Not-divisible Number
|
ユーザー |
![]() |
提出日時 | 2023-04-02 18:56:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 540 ms / 2,000 ms |
コード長 | 949 bytes |
コンパイル時間 | 1,271 ms |
コンパイル使用メモリ | 104,552 KB |
最終ジャッジ日時 | 2025-02-11 22:24:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> #include <cassert> using namespace std; using ll = long long; ll A, B, C, K; bool judge(ll X){ return X-(X/A+X/B-X/C) <= K; } void solve(){ cin >> A >> B >> K; assert(A != B); assert(2 <= A && A <= 1e9); assert(2 <= B && B <= 1e9); assert(1 <= K && K <= 1e18); C = A*B/gcd(A,B); ll l=0, r=4e18, c; while(r-l>1){ c = (l+r)/2; if (judge(c)) l=c; else r=c; } ll mi=max(1LL, l-5); for (ll X=mi; X<=l; X++){ if (X-(X/A+X/B-X/C) == K && X % A != 0 && X % B != 0){ cout << X << endl; return; } } assert(false); return; } int main(){ ll T; cin >> T; while(T){ T--; solve(); } return 0; }