結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 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 1 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 2 ms
5,376 KB
testcase_10 AC 187 ms
5,376 KB
testcase_11 AC 202 ms
5,376 KB
testcase_12 AC 786 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 180 ms
5,376 KB
testcase_16 AC 796 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 273 ms
5,376 KB
testcase_22 AC 235 ms
5,376 KB
testcase_23 AC 800 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 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 278 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 257 ms
5,376 KB
testcase_34 AC 800 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 806 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 784 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 = static_modint<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