結果

問題 No.1312 Snake Eyes
ユーザー
提出日時 2020-12-09 00:34:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 92,900 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-18 22:21:52
合計ジャッジ時間 3,016 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n;
bool solve(long long x, long long y, long long z) {
	long long co = 0;
	long long now = 1;
	for (long long i = 0; i < z; i++) {
		co += now * y;
		if (100000000000000000 / now < x) {
			return true;
		}
		now *= x;
	}
	if (co >= n) {
		return true;
	}
	else {
		return false;
	}
}
int main() {
	cin >> n;
	long long ans = 1000000000000007;
	for (long long i = 1; i <= 9; i++) {
		for (long long j = 1; j < 40; j++) {
			long long l = i, r = 2000000000000;
			while (r - l > 1) {
				long long mid = (l + r) / 2;
				if (solve(mid, i, j)) {
					r = mid;
				}
				else {
					l = mid;
				}
			}
			bool a = true;
			long long co = 0;
			long long now = 1;
			for (long long k = 0; k < j; k++) {
				co += now * i;
				if (100000000000000000 / now < r) {
					a = false;
					break;
				}
				now *= r;
			}
			if (co != n) {
				a = false;
			}
			if (a) {
				if (ans > r) {
					ans = r;
				}
			}
		}
	}
	cout << ans << endl;
}
0