結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー risujiroh
提出日時 2023-04-14 23:46:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 895 bytes
コンパイル時間 3,176 ms
コンパイル使用メモリ 245,684 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-10 14:47:39
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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;
  }

  for (int i = 0; i < 5; ++i) {
    for (int e :
         {(ans + mod / 5 * i).val(), (-ans + mod / 5 * i).val() - mod}) {
      if (-(1 << 29) <= e && e <= 1 << 29) {
        cout << e << '\n';
        return 0;
      }
    }
  }
  cout << "NaN\n";
}
0