結果

問題 No.811 約数の個数の最大化
ユーザー norioc
提出日時 2024-09-03 02:35:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 78,088 KB
最終ジャッジ日時 2024-09-03 02:35:46
合計ジャッジ時間 2,721 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from math import gcd


def factorize(n):
    p = 2
    while p * p <= n:
        while n % p == 0:
            yield p
            n //= p
        p += 1
    if n > 1:
        yield n


def number_of_divisors(n: int) -> int:
    res = 1
    for k, v in Counter(factorize(n)).items():
        res *= v+1

    return res


N, K = map(int, input().split())

dmax = 0
ans = 0
for i in range(1, N):
    g = gcd(i, N)
    np = len(list(factorize(g)))
    if np >= K:
        nd = number_of_divisors(i)
        if dmax < nd:
            dmax = nd
            ans = i

print(ans)
0