結果

問題 No.2066 Simple Math !
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 03:40:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 975 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 198,952 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-22 03:25:22
合計ジャッジ時間 15,636 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 111 ms
4,376 KB
testcase_02 AC 149 ms
4,500 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 484 ms
4,380 KB
testcase_10 AC 485 ms
4,380 KB
testcase_11 AC 479 ms
4,376 KB
testcase_12 AC 481 ms
4,380 KB
testcase_13 AC 485 ms
4,376 KB
testcase_14 AC 422 ms
4,376 KB
testcase_15 AC 425 ms
4,376 KB
testcase_16 AC 423 ms
4,376 KB
testcase_17 AC 425 ms
4,376 KB
testcase_18 AC 423 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 408 ms
4,376 KB
testcase_25 AC 407 ms
4,376 KB
testcase_26 AC 406 ms
4,380 KB
testcase_27 AC 406 ms
4,376 KB
testcase_28 AC 408 ms
4,380 KB
testcase_29 AC 71 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 58 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 << "\n";
    }
}
0