結果
| 問題 | No.2440 Accuracy of Integer Division Approximate Functions |
| ユーザー |
👑 |
| 提出日時 | 2023-08-18 01:36:52 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 1,171 bytes |
| 記録 | |
| コンパイル時間 | 5,477 ms |
| コンパイル使用メモリ | 364,704 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-29 08:01:13 |
| 合計ジャッジ時間 | 5,265 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
In file included from main.cpp:3:
In member function 'void boost::multiprecision::backends::cpp_int_base<MinBits, MaxBits, boost::multiprecision::signed_magnitude, Checked, Allocator, false>::resize(std::size_t, std::size_t) [with long unsigned int MinBits = 0; long unsigned int MaxBits = 18446744073709551615; boost::multiprecision::cpp_int_check_type Checked = boost::multiprecision::unchecked; Allocator = std::allocator<long long unsigned int>]',
inlined from 'constexpr typename std::enable_if<(std::is_same<A, long long unsigned int>::value && (! std::integral_constant<bool, boost::multiprecision::backends::is_trivial_cpp_int<boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value>::value)), boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>&>::type boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>::operator=(A) [with A = long long unsigned int; long unsigned int MinBits = 0; long unsigned int MaxBits = 0; boost::multiprecision::cpp_integer_type SignType = boost::multiprecision::signed_magnitude; boost::multiprecision::cpp_int_check_type Checked = boost::multiprecision::unchecked; Allocator = std::allocator<long long unsigned int>]' at /usr/local/include/boost/multiprecision/cpp_int.hpp:1563:19,
inlined from 'void boost::multiprecision::backends::left_shift_byte(Int&, boost::multiprecision::double_limb_type) [with Int = cpp_int_backend<>]' at /usr/local/include/boost/multiprecision/cpp_int/bitwise.hpp:347:14,
inlined from 'constexpr typename std::enable_if<(! boost::multiprecision::backends::is_trivial_cpp_int<boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value)>::type boost::multiprecision::backends::eval_left_shift(cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>&, boost::multiprecision::double_limb_type) [with long unsigned int MinBits1 = 0;
ソースコード
#include <iostream> // cin, cout, ios
#include <utility> // swap
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
mp::cpp_int floor_sum_unsigned(mp::cpp_int n, mp::cpp_int m, mp::cpp_int a, mp::cpp_int b) {
mp::cpp_int ans = 0;
for(;;) {
if (a >= m) {
ans += (n * (n - 1) >> 1) * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
mp::cpp_int ymax = a * n + b;
if (ymax < m) {
return ans;
}
n = ymax / m;
b = ymax % m;
std::swap(a, m);
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int q;
std::cin >> q;
for (int i = 0; i < q; i++) {
mp::cpp_int n, d, m; int s;
std::cin >> n >> d >> m >> s;
mp::cpp_int pow2s = (mp::cpp_int)1 << s, dm = d * m;
if (pow2s != dm) {
n = mp::min(n, d * pow2s / mp::abs(dm - pow2s));
n -= mp::abs(floor_sum_unsigned(n + 1, pow2s, m, 0) - floor_sum_unsigned(n + 1, d, 1, 0));
}
std::cout << n << '\n';
}
return 0;
}