結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-06-06 00:11:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 186 ms / 2,000 ms |
| コード長 | 1,779 bytes |
| コンパイル時間 | 805 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 78,296 KB |
| 最終ジャッジ日時 | 2024-09-21 04:24:30 |
| 合計ジャッジ時間 | 2,928 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')
def index_lt(a, x):
'return largest index s.t. A[i] < x or -1 if it does not exist'
return bisect.bisect_left(a, x) - 1
def index_le(a, x):
'return largest index s.t. A[i] <= x or -1 if it does not exist'
return bisect.bisect_right(a, x) - 1
def index_gt(a, x):
'return smallest index s.t. A[i] > x or len(a) if it does not exist'
return bisect.bisect_right(a, x)
def index_ge(a, x):
'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
return bisect.bisect_left(a, x)
class Osa_k:
# N以下の整数を素因数分解 O(NlogN)
def __init__(self, N):
self.min_factor = [i for i in range(N + 1)]
for i in range(2, N + 1):
if i * i > N:
break
if self.min_factor[i] == i:
for j in range(2, N + 1):
if i * j > N:
break
if self.min_factor[i * j] > i:
self.min_factor[i * j] = i
def factors(self, n):
d = defaultdict(int)
while n > 1:
d[self.min_factor[n]] += 1
n //= self.min_factor[n]
return d
N, K = map(int, input().split())
osa_k = Osa_k(N)
fn = osa_k.factors(N)
ma_divs = 0
for i in range(1, N):
fi = osa_k.factors(i)
cnt = 0
for k in fn.keys():
cnt += min(fn[k], fi[k])
if cnt < K:
continue
n_divs = 1
for v in fi.values():
n_divs *= (v + 1)
if n_divs > ma_divs:
ma_divs = n_divs
ans = i
print(ans)
terasa