結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
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 1 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 1 ms
5,376 KB
testcase_26 AC 2 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,long long cv = 0,long long c5 = 1,long long c2 = t){
	N %= c2;
	while(N<0)N += c2;
	if(c2==0)return;
	if(N%c2==0){
		S.insert(cv);
		return;
	}
	
	if(N%5==0){
		dfs(N/5,cv,c5*5,c2/5);
	}
	else if(N%5==1){
		dfs((N-1)/5,cv+c5,c5*5,c2/5);
		dfs((N-16)/5,cv+c5*4,c5*5,c2/5);
	}
	else if(N%5==4){
		dfs((N-4)/5,cv+c5*2,c5*5,c2/5);
		dfs((N-9)/5,cv+c5*3,c5*5,c2/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);
	//cout<<S.size()<<endl;
	for(auto a:S){
		long long tt = a;
		tt %= t;
		while(tt>(1LL<<29))tt -= t;
		while(tt<-(1LL<<29))tt += t;
		if((-(1LL<<29)<=tt && tt<=(1LL<<29))){
			cout<<tt<<endl;
			return 0;
		}
	}
	
	cout<<"NaN"<<endl;
	
	return 0;
}
0