結果

問題 No.1312 Snake Eyes
ユーザー H20
提出日時 2020-12-10 10:57:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 999 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 81,920 KB
最終ジャッジ日時 2024-09-19 18:45:14
合計ジャッジ時間 13,020 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 73 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i < n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors+upper_divisors[::-1]

#めぐる式二部探索
#参考サイト:https://aotamasaki.hatenablog.com/entry/meguru_bisect

def is_ok(arg,tar,n):
    return (arg**n-1)//(arg-1) <= tar

def meguru_bisect(ng, ok, tar, n):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,tar,n):
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
L=make_divisors(N)
ans = N-1
if N == 1:
    print(2)
    exit()
if N == 2:
    print(3)
    exit()


for l in L:
    for i in range(2,41):
        temp = meguru_bisect(10**12+1, 2 ,l ,i)
        if temp>N//l and (temp**i-1)//(temp-1)==l:
            ans = min(temp,ans)
        if temp == 1:
            break

print(ans)
0