結果
| 問題 | No.2976 高階多点評価 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-05 01:11:59 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 892 ms / 1,000 ms |
| + 618µs | |
| コード長 | 1,958 bytes |
| 記録 | |
| コンパイル時間 | 5,893 ms |
| コンパイル使用メモリ | 440,660 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-08-05 01:12:34 |
| 合計ジャッジ時間 | 27,893 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 |
ソースコード
#include <iostream>
#include <iomanip>
#include <ranges>
#include <variant>
#include <boost/multiprecision/cpp_int.hpp>
int main() {
using namespace std;
using bigint = boost::multiprecision::cpp_int;
ios::sync_with_stdio(false);
cin.tie(nullptr);
unsigned T;
cin >> T;
for ([[maybe_unused]] const auto _ : views::repeat(monostate{}, T)) [] {
unsigned N;
double _x;
cin >> N >> _x;
int X = round(_x * 100000), Y = 100000;
int g{gcd(X, Y)};
X /= g;
Y /= g;
bigint real = 1, imag = 0;
for (unsigned i{8}; i--; ) {
tie(real, imag) = pair<bigint, bigint>{(real + imag) * (real - imag), real * imag * 2};
if (N + 1 >> i & 1)
tie(real, imag) = pair<bigint, bigint>{-real * X - imag * Y, real * Y - imag * X};
}
long abs_sq = static_cast<long>(X) * X + static_cast<long>(Y) * Y;
bigint ans;
if (N % 2 == 0) {
ans = max(imag, -imag) * g / boost::multiprecision::pow(bigint{abs_sq}, N / 2);
} else if (int abs_round = round(sqrt(abs_sq)); abs_sq == static_cast<long>(abs_round) * abs_round) {
ans = max(imag, -imag) * g / boost::multiprecision::pow(bigint{abs_round}, N);
} else {
bigint mag_sq = imag * g * (imag * g) / boost::multiprecision::pow(bigint{abs_sq}, N);
ans = static_cast<bigint>(sqrt(static_cast<double>(mag_sq)) + 1);
do ans = (ans + mag_sq / ans) / 2; while (mag_sq != 0 && mag_sq / ans / ans == 0);
}
if (ans < 100000) {
ans -= 100;
cout << ((imag < 0) ^ (ans < 0) ? "-" : "") << abs(ans) / 100000 << "." << setw(5) << setfill('0') << abs(ans) % 100000 << '\n';
} else {
ans *= 999;
cout << (imag < 0 ? "-" : "") << ans / 100000000 << "." << setw(8) << setfill('0') << ans % 100000000 << '\n';
}
}();
return 0;
}