結果

問題 No.1312 Snake Eyes
ユーザー FromBooskaFromBooska
提出日時 2023-08-31 20:12:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 860 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 78,752 KB
最終ジャッジ日時 2023-08-31 20:13:07
合計ジャッジ時間 13,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,976 KB
testcase_01 AC 69 ms
71,240 KB
testcase_02 AC 71 ms
71,296 KB
testcase_03 AC 69 ms
70,848 KB
testcase_04 AC 69 ms
71,300 KB
testcase_05 AC 70 ms
71,084 KB
testcase_06 AC 70 ms
70,996 KB
testcase_07 AC 69 ms
71,244 KB
testcase_08 AC 66 ms
71,320 KB
testcase_09 AC 68 ms
71,296 KB
testcase_10 AC 68 ms
70,904 KB
testcase_11 AC 70 ms
70,852 KB
testcase_12 AC 69 ms
71,128 KB
testcase_13 AC 72 ms
71,036 KB
testcase_14 AC 67 ms
71,344 KB
testcase_15 AC 67 ms
71,196 KB
testcase_16 AC 68 ms
70,904 KB
testcase_17 AC 68 ms
70,996 KB
testcase_18 AC 68 ms
71,104 KB
testcase_19 AC 68 ms
71,340 KB
testcase_20 AC 70 ms
70,848 KB
testcase_21 AC 74 ms
71,092 KB
testcase_22 AC 72 ms
71,164 KB
testcase_23 AC 75 ms
75,132 KB
testcase_24 AC 72 ms
75,192 KB
testcase_25 AC 72 ms
75,132 KB
testcase_26 AC 72 ms
75,212 KB
testcase_27 AC 72 ms
74,836 KB
testcase_28 AC 73 ms
75,428 KB
testcase_29 AC 73 ms
75,044 KB
testcase_30 AC 72 ms
74,980 KB
testcase_31 AC 73 ms
75,184 KB
testcase_32 AC 71 ms
75,176 KB
testcase_33 AC 71 ms
70,860 KB
testcase_34 AC 77 ms
75,832 KB
testcase_35 AC 73 ms
75,128 KB
testcase_36 AC 70 ms
75,180 KB
testcase_37 AC 71 ms
75,068 KB
testcase_38 AC 72 ms
75,188 KB
testcase_39 AC 73 ms
75,112 KB
testcase_40 AC 73 ms
75,076 KB
testcase_41 AC 77 ms
75,052 KB
testcase_42 AC 76 ms
75,188 KB
testcase_43 AC 74 ms
75,188 KB
testcase_44 AC 73 ms
75,400 KB
testcase_45 AC 72 ms
75,172 KB
testcase_46 AC 71 ms
75,168 KB
testcase_47 AC 71 ms
75,184 KB
testcase_48 AC 201 ms
76,364 KB
testcase_49 AC 139 ms
75,768 KB
testcase_50 AC 103 ms
75,196 KB
testcase_51 AC 89 ms
75,032 KB
testcase_52 AC 114 ms
75,476 KB
testcase_53 AC 133 ms
75,348 KB
testcase_54 AC 108 ms
75,144 KB
testcase_55 AC 91 ms
75,180 KB
testcase_56 AC 120 ms
76,112 KB
testcase_57 AC 102 ms
75,032 KB
testcase_58 AC 130 ms
75,180 KB
testcase_59 AC 95 ms
75,744 KB
testcase_60 AC 93 ms
75,316 KB
testcase_61 AC 127 ms
75,744 KB
testcase_62 AC 98 ms
75,284 KB
testcase_63 AC 71 ms
75,144 KB
testcase_64 AC 71 ms
75,284 KB
testcase_65 AC 73 ms
75,112 KB
testcase_66 AC 72 ms
75,168 KB
testcase_67 AC 69 ms
71,104 KB
testcase_68 AC 73 ms
75,160 KB
testcase_69 AC 81 ms
75,216 KB
testcase_70 AC 130 ms
75,240 KB
testcase_71 AC 97 ms
75,200 KB
testcase_72 AC 76 ms
75,440 KB
testcase_73 AC 72 ms
75,172 KB
testcase_74 AC 70 ms
75,180 KB
testcase_75 AC 72 ms
75,212 KB
testcase_76 AC 860 ms
78,752 KB
testcase_77 AC 101 ms
74,884 KB
testcase_78 AC 103 ms
75,052 KB
testcase_79 AC 105 ms
75,448 KB
testcase_80 AC 111 ms
76,120 KB
testcase_81 AC 113 ms
75,204 KB
testcase_82 AC 171 ms
75,648 KB
testcase_83 AC 186 ms
76,288 KB
testcase_84 AC 101 ms
75,180 KB
testcase_85 AC 129 ms
75,284 KB
testcase_86 AC 163 ms
75,264 KB
testcase_87 AC 87 ms
75,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 単調性はないので二分探索は無理
# 実験するとわかるのだがNの約数dに対して、d-1
# さらにd-1の約数、がpになりうる

def base_k(num, k):
    result = set()
    while num > 0:
        amari = num%k
        result.add(amari)
        num -= amari
        num //= k
    #print(result)
    return len(result)

def 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]

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

p_candidates = set()
N_divs = divisors(N)
for d in N_divs:
    d1_divs = set(divisors(d-1))
    p_candidates |= d1_divs
p_candidates.discard(0)
p_candidates.discard(1)
p_candidates = sorted(list(p_candidates))
#print(p_candidates)
for p in p_candidates:
    calc = base_k(N, p)
    #print('p', p, 'calc', calc)
    if calc==1:
        print(p)
        break
0