結果

問題 No.811 約数の個数の最大化
コンテスト
ユーザー FromBooska
提出日時 2023-09-21 19:03:49
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,022 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 294 ms
コンパイル使用メモリ 85,136 KB
実行使用メモリ 82,964 KB
最終ジャッジ日時 2026-03-29 03:04:18
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 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