結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2023-04-14 22:14:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,392 ms / 2,000 ms
コード長 1,339 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 117,256 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 19:43:30
合計ジャッジ時間 12,298 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 79 ms
6,940 KB
testcase_11 AC 56 ms
6,940 KB
testcase_12 AC 1,381 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 51 ms
6,944 KB
testcase_16 AC 1,372 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1,008 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 66 ms
6,944 KB
testcase_23 AC 1,392 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 602 ms
6,940 KB
testcase_28 AC 322 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 993 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 69 ms
6,944 KB
testcase_34 AC 1,373 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1,009 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

using P = pair<ll, int>;

void chmin(ll & x, ll y) { x = min(x, y); }

int cnt(ll x) {
	int res = 0;
	while (x % 5 == 0) {
		x /= 5;
		res++;
	}
	return res;
}

int main()
{
	int n, e;
	cin >> n >> e;
	if (e == 0) {
		cout << 0 << endl;
		return 0;
	}

	int rem = ((n % 5) + 5) % 5;
	if (rem == 2 || rem == 3) {
		cout << "NaN" << endl;
		return 0;
	}

	int mx = 1 << 29;
	vi<int> cand;
	if (rem == 0) cand = { 0 };
	else if (rem == 1) cand = { 1, 4 };
	else cand = { 2, 3 };

	for (int elem : cand) {
		for (ll i = elem; i <= mx; i += 5) {
			if (i * i == n) {
				cout << i << endl;
				return 0;
			}
			int res = cnt(n - i * i);
			if (res >= e) {
				cout << i << endl;
				return 0;
			}
		}

		for (ll i = elem; i >= -mx; i -= 5) {
			if (i * i == n) {
				cout << i << endl;
				return 0;
			}
			int res = cnt(n - i * i);
			if (res >= e) {
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << "NaN" << endl;
	return 0;
}
0