結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー jinya nakamurajinya nakamura
提出日時 2023-04-15 10:26:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,370 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 199,164 KB
実行使用メモリ 17,096 KB
最終ジャッジ日時 2024-04-19 06:10:26
合計ジャッジ時間 8,737 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef unsigned long long ull;
// const ll INF = numeric_limits<ll>::max() / 4;
// const int INF = numeric_limits<int>::max() / 4;
// cout << std::fixed << std::setprecision(15);


int main() {
	ll N; int E;
	cin >> N >> E;
	int K = 20;
	ll EPS = 1;
	for(int i = 0; i < K; i++) EPS *= 5;
	if(N < 0) N += EPS;

	ll D = 0;
	while(N % 5 == 0){
		N /= 5;
		D++;
	}
	if(D % 2 == 1){
		cout << "NaN" << endl;
		return 0;
	}

	vector<ll> T(K, 0);
	for(int k = 0; k < K; k++){
		T[k] = N % 5LL;
		N /= 5;
	}


	vector<ll> R(K, 0);
	vector<ll> U(K, 0);
	for(int e = 0; e < E - D; e++){
		ll l = U[e];
		U[e] = 0;
		for(int j = 1; j <= e - 1; j++){
			l += R[j] * R[e - j];
		}
		bool f = false;
		for(R[e] = 0; R[e] < 5; R[e]++){
			ll s = R[e] * R[0] * 2;
			if(e == 0) s = R[0] * R[0];
			if((l + s) % 5 == T[e]){
				l += s;
				l /= 5;
				for(int j = e + 1; j < K; j++){
					U[j] += l % 5;
					l /= 5;
				}
				f = true;
				break;
			}
		}
		if(!f){
			cout << "NaN" << endl;
			return 0;
		}
	}

	ll r = 0;
	ll d = 1;
	for(int k = 0; k <= K; k++){
		r += R[k] * d;
		d *= 5LL;
	}
	for(int i = 0; i < D / 2; i++) r *= 5;

	EPS = 1;
	for(int i = 0; i < E; i++) EPS *= 5;
	while((1LL << 29) < r) r -= EPS;
	if(r < -(1LL << 29)){
		cout << "NaN" << endl;
	}else{
		cout << r << endl;
	}

	return 0;
}
0