結果
| 問題 |
No.2066 Simple Math !
|
| コンテスト | |
| ユーザー |
NAMIDAIRO
|
| 提出日時 | 2022-09-04 15:11:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,305 bytes |
| コンパイル時間 | 851 ms |
| コンパイル使用メモリ | 76,840 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-18 20:26:54 |
| 合計ジャッジ時間 | 8,734 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 WA * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dump(x) cout << #x << " = " << (x) << endl;
template<class T>
using vi = vector<T>;
template<class T>
using vii = vector<vi<T>>;
template<class T>
using viii = vector<vii<T>>;
template<class T>
T floor_sum(T n, T m, T a, T b) { //sigma(i=0~n-1){[(ai+b)/m]}
T res = 0;
res += (a / m) * n * (n - 1) / 2;
res += (b / m) * n;
a = a % m;
b = b % m;
T ymax = a * n + b;
if (ymax < m) return res;
res += floor_sum(ymax / m, a, m, ymax % m);
return res;
}
int main()
{
int t;
cin >> t;
//yukicoder 2066
while (t--) {
ll p, q, k;
cin >> p >> q >> k;
ll ok = 0, ng = min(p, q) * k + 1;
while (ng - ok > 1) {
ll mid = (ok + ng) / 2;
ll cnt = min(mid / q, p - 1);
ll n = mid / q + 1;
ll m = p;
ll a = q;
ll b = mid % q;
cnt += floor_sum<ll>(n, m, a, b);
if (n >= p) cnt -= floor_sum<ll>(n - p, m, a, b);
if (cnt < k) ok = mid;
else ng = mid;
}
cout << ng << endl;
}
return 0;
}
NAMIDAIRO