結果

問題 No.1312 Snake Eyes
ユーザー rlangevin
提出日時 2023-04-17 19:32:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 740 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 81,024 KB
最終ジャッジ日時 2024-10-12 20:42:20
合計ジャッジ時間 7,322 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 TLE * 1 -- * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
if N == 1:
    print(2)
    exit()
if N == 2:
    print(3)
    exit()

inf = 10 ** 18
def f(p, d):
    if p >= 10 ** 9 and d >= 3:
        return inf
    if p >= 10 ** 6 and d >= 4:
        return inf
    if p >= 10 ** 4 and d >= 5:
        return inf
    return (p ** d - 1) // (p - 1)

ans = N - 1
for d in range(2, 45):
    for v in range(1, 10**18):
        if v * f(v + 1, d) > N:
            break
        yes = v + 1
        no = N + 1
        if no <= yes:
            break
        while no - yes != 1:
            mid = (yes + no)//2
            if v * f(mid, d) <= N:
                yes = mid
            else:
                no  = mid
        if v * f(yes, d) == N:
            ans = min(ans, yes)

print(ans)
0