結果

問題 No.2976 高階多点評価
コンテスト
ユーザー 259-Momone
提出日時 2026-08-05 01:07:15
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,689 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,933 ms
コンパイル使用メモリ 439,532 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-05 01:07:39
合計ジャッジ時間 23,110 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 / ans / ans == 0);
        }
        cout << (imag < 0 ? "-" : "") << ans / 100000 << "." << setw(5) << setfill('0') << ans % 100000 << '\n';
    }();
    return 0;
}
0