結果

問題 No.811 約数の個数の最大化
ユーザー terasaterasa
提出日時 2022-06-06 00:11:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 77,676 KB
最終ジャッジ日時 2023-10-21 03:22:21
合計ジャッジ時間 3,143 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,612 KB
testcase_01 AC 76 ms
68,732 KB
testcase_02 AC 172 ms
77,484 KB
testcase_03 AC 48 ms
55,648 KB
testcase_04 AC 56 ms
63,840 KB
testcase_05 AC 84 ms
76,416 KB
testcase_06 AC 113 ms
76,900 KB
testcase_07 AC 97 ms
76,464 KB
testcase_08 AC 144 ms
77,344 KB
testcase_09 AC 121 ms
76,924 KB
testcase_10 AC 108 ms
76,652 KB
testcase_11 AC 156 ms
77,412 KB
testcase_12 AC 118 ms
77,008 KB
testcase_13 AC 153 ms
77,408 KB
testcase_14 AC 173 ms
77,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0