結果

問題 No.1312 Snake Eyes
ユーザー H20
提出日時 2020-12-09 23:09:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,824 KB
実行使用メモリ 82,996 KB
最終ジャッジ日時 2024-09-19 05:42:17
合計ジャッジ時間 8,918 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 67 WA * 6 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

#約数の後半列挙
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 upper_divisors[::-1]

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

def is_ok(arg,tar,n):
    # 整数を買えればTrueを返す
    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

L=make_divisors(N)
ans = N-1

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

print(ans)
0