結果

問題 No.1312 Snake Eyes
ユーザー tamatotamato
提出日時 2020-12-11 14:50:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 674 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,028 KB
最終ジャッジ日時 2024-11-30 13:06:25
合計ジャッジ時間 8,649 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 85
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())

    if N == 1:
        print(2)
        exit()
    elif N == 2:
        print(3)
        exit()

    for i in range(2, N+1):
        A = set()
        x = N
        cnt = 0
        while x:
            A.add(x % i)
            x //= i
            cnt += 1
        if cnt <= 2:
            break
        if len(A) == 1:
            print(i)
            exit()
    ans = N - 1
    for d in range(2, N+1):
        p = N // d - 1
        if p <= d:
            break
        if N % d == 0:
            ans = p
    print(ans)


if __name__ == '__main__':
    main()
0