結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2023-09-21 19:03:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 423 ms / 2,000 ms |
コード長 | 1,022 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 82,008 KB |
実行使用メモリ | 78,088 KB |
最終ジャッジ日時 | 2024-07-07 12:38:54 |
合計ジャッジ時間 | 4,282 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
# N<10**5なので全探索可能from collections import defaultdict# 辞書型に改造def factorization(n):arr = defaultdict(int)temp = nfor i in range(2, int(-(-n**0.5//1))+1):if temp%i==0:cnt=0while temp%i==0:cnt+=1temp //= iarr[i] = cntif temp!=1:arr[temp] = 1if arr==[]:arr[n] = 1return arr#factorization(7)N, K = map(int, input().split())N_factors = factorization(N)mx_count = 0candidates = []for n in range(1, N):common = 0factors = factorization(n)count = 1for 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 = countcandidates = []candidates.append(n)elif count == mx_count:candidates.append(n)ans = min(candidates)print(ans)