結果
| 問題 | 
                            No.2271 平方根の13桁精度近似計算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             NAMIDAIRO
                         | 
                    
| 提出日時 | 2023-04-14 22:14:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,648 ms / 2,000 ms | 
| コード長 | 1,339 bytes | 
| コンパイル時間 | 1,067 ms | 
| コンパイル使用メモリ | 112,720 KB | 
| 最終ジャッジ日時 | 2025-02-12 06:56:06 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 40 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T>
using vi = vector<T>;
template<class T>
using vii = vector<vi<T>>;
template<class T>
using viii = vector<vii<T>>;
using P = pair<ll, int>;
void chmin(ll & x, ll y) { x = min(x, y); }
int cnt(ll x) {
	int res = 0;
	while (x % 5 == 0) {
		x /= 5;
		res++;
	}
	return res;
}
int main()
{
	int n, e;
	cin >> n >> e;
	if (e == 0) {
		cout << 0 << endl;
		return 0;
	}
	int rem = ((n % 5) + 5) % 5;
	if (rem == 2 || rem == 3) {
		cout << "NaN" << endl;
		return 0;
	}
	int mx = 1 << 29;
	vi<int> cand;
	if (rem == 0) cand = { 0 };
	else if (rem == 1) cand = { 1, 4 };
	else cand = { 2, 3 };
	for (int elem : cand) {
		for (ll i = elem; i <= mx; i += 5) {
			if (i * i == n) {
				cout << i << endl;
				return 0;
			}
			int res = cnt(n - i * i);
			if (res >= e) {
				cout << i << endl;
				return 0;
			}
		}
		for (ll i = elem; i >= -mx; i -= 5) {
			if (i * i == n) {
				cout << i << endl;
				return 0;
			}
			int res = cnt(n - i * i);
			if (res >= e) {
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << "NaN" << endl;
	return 0;
}
            
            
            
        
            
NAMIDAIRO