結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 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 = 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)
FromBooska