結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー KudeKude
提出日時 2023-04-14 23:49:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 1,551 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 218,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:23:55
合計ジャッジ時間 10,383 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr int pow5(int e) {
  int res = 1;
  rep(_, e) res *= 5;
  return res;
}

template<int e>
void solve(int n) {
  if (e == 0) {
    cout << 0 << '\n';
    return;
  }
  constexpr int mod = pow5(e);
  using mint = modint;
  mint::set_mod(mod);
  constexpr int mx = min(1 << 29, (mod + 1) / 2);
  mint tgt = n;
  for(int i = 0; i <= mx; i++) {
    mint r = mint::raw(i);
    mint r2 = r * r;
    if (r2 == tgt) {
      cout << r.val() << '\n';
      return;
    }
  }
  cout << "NaN\n";
}

template<int e>
void select_solver(int n, int e_in) {
  if (e_in == e) solve<e>(n);
  else select_solver<e-1>(n, e_in);
}

template<>
void select_solver<-1>(int, int) {
  assert(false);
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, e;
  cin >> n >> e;
  select_solver<13>(n, e);
  cout << flush;
}
0