結果

問題 No.811 約数の個数の最大化
ユーザー yomo3yomo3
提出日時 2020-06-09 11:45:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 77,364 KB
最終ジャッジ日時 2023-08-30 04:26:52
合計ジャッジ時間 3,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,668 KB
testcase_01 AC 85 ms
76,032 KB
testcase_02 AC 75 ms
71,680 KB
testcase_03 AC 75 ms
71,752 KB
testcase_04 AC 76 ms
71,760 KB
testcase_05 AC 80 ms
76,060 KB
testcase_06 AC 76 ms
71,472 KB
testcase_07 AC 81 ms
75,988 KB
testcase_08 WA -
testcase_09 AC 98 ms
76,908 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 210 ms
77,364 KB
testcase_14 AC 74 ms
71,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factors(n):
    f = []
    c = 0
    while n % 2 == 0:
        n //= 2
        c += 1
    if c > 0:
        f.append([2, c])
    p = 3
    while p * p <= n:
        if n % p == 0:
            c = 0
            while n % p == 0:
                n //= p
                c += 1
            if c > 0:
                f.append([p, c])
        p += 2
    if n != 1:
        f.append([n, 1])
    return f

def divisors(n):
    divs = []
    for d in range(1, int(n**0.5) + 1):
        if n % d == 0:
            divs.append(d)
            q = n // d
            if q != d:
                divs.append(q)
    return divs

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

nf = factors(N)

m = 1
i = 0
while K > 0:
    if nf[i][1] > 0:
        m *= nf[i][0]
        nf[i][1] -= 1
        K -= 1
    i = (i + 1) % len(nf)

ans = 0
max_divs = 0

M = m
while M < N:
    divs = len(divisors(M))
    if divs > max_divs:
        ans = M
        max_divs = divs
    M += m

print(ans)
0