結果
| 問題 |
No.2440 Accuracy of Integer Division Approximate Functions
|
| ユーザー |
👑 |
| 提出日時 | 2023-08-31 18:58:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 919 bytes |
| コンパイル時間 | 10,347 ms |
| コンパイル使用メモリ | 319,524 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-03 04:46:57 |
| 合計ジャッジ時間 | 12,528 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream> // cin, cout, ios
#include <utility> // swap
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using bint = mp::cpp_int;
bint floor_sum_unsigned(bint n, bint m, bint a, bint b) {
bint r = 0, y;
while(n > 0) {
r += a / m * (n * (n - 1) >> 1) + b / m * n;
a %= m;
y = a * n + b % m;
n = y / m;
b = y % m;
std::swap(a, m);
}
return r;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int q, s;
bint n, d, m, t, u;
std::cin >> q;
for (int i = 0; i < q; i++) {
std::cin >> n >> d >> m >> s;
t = (bint)1 << s, u = d * m;
if (t != u) {
n = mp::min(n, d * t / mp::abs(t - u));
n -= mp::abs(floor_sum_unsigned(n + 1, t, m, 0) - floor_sum_unsigned(n + 1, d, 1, 0));
}
std::cout << n << '\n';
}
}