結果
| 問題 | 
                            No.2271 平方根の13桁精度近似計算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             沙耶花
                         | 
                    
| 提出日時 | 2023-04-14 23:19:02 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,089 bytes | 
| コンパイル時間 | 3,611 ms | 
| コンパイル使用メモリ | 256,132 KB | 
| 最終ジャッジ日時 | 2025-02-12 08:13:18 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 WA * 7 | 
ソースコード
#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==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;
}
            
            
            
        
            
沙耶花