結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 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 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 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 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 0 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 WA -
testcase_34 AC 2 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 2 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 t = 1;
set<long long> S;
void dfs(long long N,int cur = 0,long long cv = 0,long long c5 = 1){
	
	while(N<0)N += 5;
	
	if(N%t==0){
		S.insert(cv);
		return;
	}
	if(cur == 14)return;
	if(N%5==0){
		dfs(N/5,cur+1,cv,c5*5);
	}
	else if(N%5==1){
		dfs((N+t*100-1)/5,cur+1,cv+c5,c5*5);
		dfs((N+t*100-16)/5,cur+1,cv+c5*4,c5*5);
	}
	else if(N%5==4){
		dfs((N+t*100-4)/5,cur+1,cv+c5*2,c5*5);
		dfs((N+t*100-9)/5,cur+1,cv+c5*3,c5*5);
	}
	
}
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;
		}
	}
	
	
	rep(i,E)t *= 5;
	N %= t;
	if(N<0)N += t;
	dfs(N);
	
	for(auto a:S){
		long long tt = a;
		tt %= t;
		if(tt>(1LL<<29))tt -= t;
		if(tt<-(1LL<<29))tt += t;
		if((-(1LL<<29)<=tt && tt<=(1LL<<29))){
			cout<<tt<<endl;
			return 0;
		}
	}
	
	cout<<"NaN"<<endl;
	
	return 0;
}
0