結果

問題 No.2066 Simple Math !
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 03:41:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 485 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 197,716 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 03:25:52
合計ジャッジ時間 14,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 110 ms
4,380 KB
testcase_02 AC 147 ms
4,376 KB
testcase_03 AC 32 ms
4,380 KB
testcase_04 AC 482 ms
4,376 KB
testcase_05 AC 481 ms
4,380 KB
testcase_06 AC 482 ms
4,376 KB
testcase_07 AC 485 ms
4,380 KB
testcase_08 AC 481 ms
4,380 KB
testcase_09 AC 480 ms
4,384 KB
testcase_10 AC 485 ms
4,376 KB
testcase_11 AC 480 ms
4,380 KB
testcase_12 AC 483 ms
4,376 KB
testcase_13 AC 485 ms
4,376 KB
testcase_14 AC 423 ms
4,376 KB
testcase_15 AC 422 ms
4,376 KB
testcase_16 AC 423 ms
4,376 KB
testcase_17 AC 426 ms
4,376 KB
testcase_18 AC 427 ms
4,380 KB
testcase_19 AC 265 ms
4,380 KB
testcase_20 AC 264 ms
4,376 KB
testcase_21 AC 264 ms
4,376 KB
testcase_22 AC 267 ms
4,384 KB
testcase_23 AC 266 ms
4,376 KB
testcase_24 AC 408 ms
4,376 KB
testcase_25 AC 408 ms
4,376 KB
testcase_26 AC 406 ms
4,380 KB
testcase_27 AC 409 ms
4,376 KB
testcase_28 AC 408 ms
4,376 KB
testcase_29 AC 72 ms
4,380 KB
testcase_30 AC 34 ms
4,376 KB
testcase_31 AC 59 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int maxn=1000005,mod=1000000007;
ll floor_sum(ll n, ll m, ll a, ll b) {
  ll ans = 0;
  if (a >= m) ans += (n - 1) * n * (a / m) / 2, a %= m;
  if (b >= m) ans += n * (b / m), b %= m;
  ll y_max = (a * n + b) / m, x_max = (y_max * m - b);
  if (y_max == 0) return ans;
  ans += (n - (x_max + a - 1) / a) * y_max;
  ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
  return ans;
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int t; cin >> t;
    while(t--){
        int x,y,k; cin >> x >> y >> k;
        int g=__gcd(x,y); x/=g,y/=g;
        ll l=1,r=1e18;
        while(l<r){
            ll mid=l+r>>1;
            ll m=min(mid/x+1,(ll)y);
            if(floor_sum(m,y,x,mid-(m-1)*x)+m>=k+1) r=mid;
            else l=mid+1;
        }
        cout << l*g << "\n";
    }
}
0