結果

問題 No.2976 高階多点評価
コンテスト
ユーザー 259-Momone
提出日時 2026-08-05 00:43:21
言語 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  
実行時間 -
コード長 2,435 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,008 ms
コンパイル使用メモリ 679,148 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-05 00:43:55
合計ジャッジ時間 30,340 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 30 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/extc++.h>
#include <boost/multiprecision/cpp_int.hpp>

int main() {
    using namespace std;
    using bigint = boost::multiprecision::cpp_int;
    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 * real - imag * 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;
        int abs_round = round(sqrt(abs_sq));
        bigint ans;
        if (abs_sq == static_cast<long>(abs_round) * abs_round) {
            bigint abs_ans = boost::multiprecision::pow(bigint{abs_round}, N);
            ans = max(imag, -imag) * g / abs_ans;
        } else if (N == 1) {
            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);
            if (mag_sq != 0) {
                do {
                    ans = (ans + mag_sq / ans) / 2;
                } while (mag_sq / ans / ans == 0);
            }
        } else if (N & 1) {
            long gi = gcd(static_cast<long>(imag % abs_sq), abs_sq);
            imag /= gi;
            abs_sq /= gi;
            long gg = gcd(g, abs_sq);
            g /= gg;
            abs_sq /= gg;
            bigint mag_sq = imag * g * (imag * g) / boost::multiprecision::pow(bigint{abs_sq}, N) / boost::multiprecision::pow(bigint{gi}, N - 2) / boost::multiprecision::pow(bigint{gg}, N - 2);
            ans = static_cast<bigint>(sqrt(static_cast<double>(mag_sq)) + 1);
            if (mag_sq != 0) {
                do {
                    ans = (ans + mag_sq / ans) / 2;
                } while (mag_sq / ans / ans == 0);
            }
        } else {
            bigint abs_ans = boost::multiprecision::pow(bigint{abs_sq}, N / 2);
            ans = max(imag, -imag) * g / abs_ans;
        }
        cout << (imag < 0 ? "-" : "") << ans / 100000 << "." << setw(5) << setfill('0') << ans % 100000 << endl;
    }();
    abort();
    return 0;
}
0