結果

問題 No.811 約数の個数の最大化
ユーザー tktk_snsntktk_snsn
提出日時 2021-04-28 18:45:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 10,068 KB
最終ジャッジ日時 2023-09-22 00:27:46
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,684 KB
testcase_01 AC 24 ms
8,916 KB
testcase_02 AC 88 ms
9,924 KB
testcase_03 AC 21 ms
8,740 KB
testcase_04 AC 21 ms
8,716 KB
testcase_05 AC 24 ms
8,744 KB
testcase_06 AC 28 ms
8,976 KB
testcase_07 AC 32 ms
8,876 KB
testcase_08 AC 55 ms
9,280 KB
testcase_09 AC 75 ms
9,460 KB
testcase_10 AC 48 ms
9,108 KB
testcase_11 AC 87 ms
9,808 KB
testcase_12 AC 41 ms
8,840 KB
testcase_13 AC 183 ms
9,840 KB
testcase_14 AC 93 ms
10,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from math import gcd
from functools import lru_cache


def prime_sieve(N):
    #sieve[i] : iの最小の素因数
    sieve = [0] * (N + 1)
    prime = []
    for i in range(2, N + 1):
        if sieve[i] == 0:
            sieve[i] = i
            prime.append(i)
        for p in prime:
            if p > sieve[i] or i * p > N:
                break
            sieve[i * p] = p
    return sieve


@lru_cache(maxsize=None)
def get_factor(N):
    cnt = 0
    while sieve[N]:
        cnt += 1
        N //= sieve[N]
    return cnt


def count_divisor(N):
    pf = []
    while sieve[N]:
        pf.append(sieve[N])
        N //= sieve[N]
    res = 1
    for v in Counter(pf).values():
        res *= v+1
    return res


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

ans = 0
div = 0
for x in reversed(range(1, N)):
    g = gcd(x, N)
    if get_factor(g) >= K:
        cnt = count_divisor(x)
        if cnt >= div:
            div = cnt
            ans = x

print(ans)
0