結果

問題 No.1312 Snake Eyes
ユーザー fairy_lettucefairy_lettuce
提出日時 2020-12-08 01:51:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 192,728 KB
最終ジャッジ日時 2025-01-16 19:27:26
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007
#define ll long long

ll power(ll a, ll p) {
	ll ret = 1;
	for (ll i = 1; i <= p; i *= 2, a *= a)
	{
		if ((i & p) > 0) ret *= a;
	}
	return ret;
}

int main() {
	ll n;
	cin >> n;

	if (n == 1) {
		cout << 2 << endl;
		return 0;
	}
	if (n == 2) {
		cout << 3 << endl;
		return 0;
	}

	ll ans = 1000000000000;

	for (ll a = 1; a * a <= n; a++)
	{
		if (n % a != 0) continue;
		ll an = n / a;
		for (int i = 2; i <= 40; i++)
		{
			if (i == 2) {
				ll p = an - 1;
				if (a < p) ans = min(ans, p);
			}
			else
			{
				ll ng = (ll)(pow(1000000000000000000, 1.0 / i) + 5);
				ll ok = 1;
				while (ng - ok > 1)
				{
					ll mid = ok + (ng - ok) / 2;
					ll t = (power(mid, i) - 1) / (mid - 1);
					if (t == an) {
						if (a < mid) {
							ans = min(ans, mid);
						}
						break;
					}
					if (t > an) ng = mid;
					else ok = mid;
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}
0