結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー risujirohrisujiroh
提出日時 2023-04-14 23:49:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,010 bytes
コンパイル時間 3,517 ms
コンパイル使用メモリ 276,332 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:24:21
合計ジャッジ時間 5,158 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;

using atcoder::modint;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, E;
  cin >> N >> E;

  if (E == 0) {
    cout << "0\n";
    return 0;
  }

  int mod = 1;
  modint ::set_mod(mod);
  modint ans = 0;
  while (E--) {
    modint::set_mod(mod * 5);
    int r = ans.val();
    bool found = false;
    for (int i = 0; i < 5; ++i) {
      auto x = modint(r + i * mod);
      if (x * x == N) {
        ans = x;
        found = true;
        break;
      }
    }
    if (!found) {
      cout << "NaN\n";
      return 0;
    }
    mod *= 5;
  }

  auto go = [&](modint x) {
    if (x * x != N) {
      return;
    }
    if (x.val() <= 1 << 29) {
      cout << x.val() << '\n';
      exit(0);
    }
    if (-(1 << 29) <= x.val() - mod) {
      cout << x.val() - mod << '\n';
      exit(0);
    }
  };

  for (int i = 0; i < 5; ++i) {
    go(ans + mod / 5 * i);
    go(-ans + mod / 5 * i);
  }
  cout << "NaN\n";
}
0