結果

問題 No.1312 Snake Eyes
ユーザー rlangevin
提出日時 2023-04-17 19:27:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 76,420 KB
最終ジャッジ日時 2024-10-12 20:37:08
合計ジャッジ時間 36,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 80 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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:
        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