結果
問題 | No.2066 Simple Math ! |
ユーザー |
![]() |
提出日時 | 2022-09-02 22:03:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,676 bytes |
コンパイル時間 | 2,177 ms |
コンパイル使用メモリ | 203,240 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-16 03:30:49 |
合計ジャッジ時間 | 7,606 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 4 ms
6,816 KB |
testcase_02 | AC | 13 ms
6,820 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 194 ms
6,816 KB |
testcase_10 | AC | 195 ms
6,820 KB |
testcase_11 | AC | 193 ms
6,816 KB |
testcase_12 | AC | 193 ms
6,816 KB |
testcase_13 | AC | 193 ms
6,816 KB |
testcase_14 | AC | 194 ms
6,820 KB |
testcase_15 | AC | 194 ms
6,816 KB |
testcase_16 | AC | 195 ms
6,816 KB |
testcase_17 | AC | 194 ms
6,820 KB |
testcase_18 | AC | 195 ms
6,816 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 96 ms
6,816 KB |
testcase_25 | AC | 96 ms
6,820 KB |
testcase_26 | AC | 96 ms
6,816 KB |
testcase_27 | AC | 95 ms
6,816 KB |
testcase_28 | AC | 95 ms
6,816 KB |
testcase_29 | AC | 50 ms
6,816 KB |
testcase_30 | WA | - |
testcase_31 | AC | 6 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=1<<30; //短い版 // from: https://gist.github.com/yosupo06/ddd51afb727600fd95d9d8ad6c3c80c9 // (based on AtCoder STL) constexpr long long safe_mod(long long x, long long m) { x %= m; if (x < 0) x += m; return x; } unsigned long long floor_sum_unsigned(unsigned long long n, unsigned long long m, unsigned long long a, unsigned long long b) { unsigned long long ans = 0; while (true) { if (a >= m) { ans += n * (n - 1) / 2 * (a / m); a %= m; } if (b >= m) { ans += n * (b / m); b %= m; } unsigned long long y_max = a * n + b; if (y_max < m) break; n = (unsigned long long)(y_max / m); b = (unsigned long long)(y_max % m); std::swap(m, a); } return ans; } long long floor_sum(long long n, long long m, long long a, long long b) { assert(0 <= n && n < (1LL << 32)); assert(1 <= m && m < (1LL << 32)); unsigned long long ans = 0; if (a < 0) { unsigned long long a2 = safe_mod(a, m); ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m); a = a2; } if (b < 0) { unsigned long long b2 = safe_mod(b, m); ans -= 1ULL * n * ((b2 - b) / m); b = b2; } return ans + floor_sum_unsigned(n, m, a, b); } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); auto solve=[&](ll P,ll Q,ll K){ if(P==1){ return K; } ll ma=P*Q-(P-1)*(Q-1)/2; if(ma<=K){ return P*Q+(K-ma); } ll left=0,right=P*Q; while(right-left>1){ ll mid=(left+right)/2; ll cn=mid/Q; ll sum=floor_sum(cn+1,P,-Q,mid)+cn+1; if(sum>K) right=mid; else left=mid; } return right; }; int QQ;cin>>QQ; while(QQ--){ ll P,Q,K;cin>>P>>Q>>K; ll g=gcd(P,Q); if(P>Q) swap(P,Q); cout<<solve(P,Q,K)*g<<"\n"; } }