結果
問題 | No.2066 Simple Math ! |
ユーザー | milanis48663220 |
提出日時 | 2022-09-02 22:32:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,572 bytes |
コンパイル時間 | 1,089 ms |
コンパイル使用メモリ | 123,168 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-27 22:09:19 |
合計ジャッジ時間 | 5,505 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 28 ms
6,944 KB |
testcase_02 | AC | 31 ms
6,940 KB |
testcase_03 | AC | 16 ms
6,940 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | AC | 18 ms
6,944 KB |
testcase_31 | AC | 28 ms
6,940 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/math> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } /** * ax + by = gcd(a, b)を満たす(x, y)をつめて、gcd(a, b)を返します。 */ template <typename T> T extGCD(T a, T b, T &x, T &y) { if (b == 0) { x = 1; y = 0; return a; } T d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } // calc ceil(a/b) template<typename T> T ceil_div(T a, T b){ return (a+b-1)/b; } void solve(){ ll p, q, k; cin >> p >> q >> k; if(p == q){ cout << p*k << endl; return; } if(p > q) swap(p, q); ll a, b; extGCD(p, q, a, b); if(a < 0){ ll x = ceil_div(-a, q); a += x*q; b -= x*p; } if(a > q){ ll x = a/q; a -= x*q; b += x*p; } b *= -1; ll g = gcd(p, q); p /= g; q /= g; function<ll(ll)> count = [&](ll x){ if(x >= p*q){ return count(p*q-1)+x-p*q+1; } ll upper = atcoder::floor_sum(x+1, q, a, 0); ll lower = atcoder::floor_sum(x+1, p, b, 0); ll on_line = x/p; return upper-lower+on_line; }; ll l = 0, r = p*q+k; while(r-l > 1){ ll x = (l+r)/2; if(count(x) >= k) r = x; else l = x; } cout << r*g << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }