結果

問題 No.811 約数の個数の最大化
ユーザー FromBooskaFromBooska
提出日時 2023-09-21 19:03:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 79,664 KB
最終ジャッジ日時 2023-09-21 19:03:54
合計ジャッジ時間 5,287 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
72,192 KB
testcase_01 AC 121 ms
79,000 KB
testcase_02 AC 522 ms
79,532 KB
testcase_03 AC 92 ms
72,224 KB
testcase_04 AC 102 ms
77,664 KB
testcase_05 AC 136 ms
79,152 KB
testcase_06 AC 173 ms
79,384 KB
testcase_07 AC 168 ms
78,920 KB
testcase_08 AC 295 ms
79,368 KB
testcase_09 AC 284 ms
79,380 KB
testcase_10 AC 220 ms
78,648 KB
testcase_11 AC 485 ms
79,416 KB
testcase_12 AC 211 ms
78,776 KB
testcase_13 AC 524 ms
79,556 KB
testcase_14 AC 556 ms
79,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# N<10**5なので全探索可能

from collections import defaultdict

# 辞書型に改造
def factorization(n):
    arr = defaultdict(int)
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt
    if temp!=1:
        arr[temp] = 1
    if arr==[]:
        arr[n] = 1
    return arr

#factorization(7)

N, K = map(int, input().split())
N_factors = factorization(N)

mx_count = 0
candidates = []
for n in range(1, N):
    common = 0
    factors = factorization(n)
    count = 1
    for p in factors:
        common += min(N_factors[p], factors[p])
        count *= (factors[p]+1)
    #print('n', n, 'common', common, 'count', count)
    if common >= K:
        if count > mx_count:
            mx_count = count
            candidates = []
            candidates.append(n)
        elif count == mx_count:
            candidates.append(n)
ans = min(candidates)
print(ans)




0