結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー 沙耶花沙耶花
提出日時 2023-04-14 23:03:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 4,371 ms
コンパイル使用メモリ 253,480 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 20:39:41
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 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 WA -
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 WA -
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

long long dfs(long long N,int cp = 0){
	if(N<0)N += 5;
	if(cp>=30)return -1;
	if(N==0)return 0;
	if(N%5==0){
		long long r = dfs(N/5,cp+1);
		if(r==-1)return r;
		return r*5;
	}
	if(N%5==1){
		long long r = dfs(N/5,cp+1);
		if(r==-1){
			dfs((N-16)/5,cp+1);
			if(r==-1)return r;
			else return r*5+4;
		}
		else return r*5+1;
	}
	if(N%5==4){
		long long r = dfs(N/5,cp+1);
		if(r==-1){
			dfs((N-9)/5,cp+1);
			if(r==-1)return r;
			else return r*5+3;
		}
		else return r*5+2;
	}
	return -1;
	
}
int main(){
	
	long long N,E;
	cin>>N>>E;
	
	if(N>=0){
		long long sq = sqrtl(N);
		if(sq*sq==N){
			cout<<sq<<endl;
			return 0;
		}
	}
	
	long long t = 1;
	rep(i,E)t *= 5;
	N %= t;
	if(N<0)N += t;
	long long ans = dfs(N);
	if(ans==-1)cout<<"NaN"<<endl;
	else cout<<ans<<endl;
	//cout<<dfs(N)<<endl;
	
	return 0;
}
0