結果

問題 No.811 約数の個数の最大化
ユーザー toyuzukotoyuzuko
提出日時 2020-05-01 22:30:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 706 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 7,932 KB
最終ジャッジ日時 2023-08-26 15:10:43
合計ジャッジ時間 2,457 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,928 KB
testcase_01 AC 17 ms
7,752 KB
testcase_02 AC 103 ms
7,820 KB
testcase_03 AC 14 ms
7,932 KB
testcase_04 AC 14 ms
7,796 KB
testcase_05 AC 18 ms
7,832 KB
testcase_06 AC 21 ms
7,832 KB
testcase_07 AC 28 ms
7,752 KB
testcase_08 AC 58 ms
7,816 KB
testcase_09 AC 141 ms
7,836 KB
testcase_10 AC 55 ms
7,828 KB
testcase_11 AC 90 ms
7,836 KB
testcase_12 AC 38 ms
7,828 KB
testcase_13 AC 706 ms
7,832 KB
testcase_14 AC 107 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def divisor(n):
    res = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            res.add(i)
            res.add(n // i)
        i += 1
    return sorted(res)

def factorize(n):
    if n == 1: return []
    res = []
    x, y = n, 2
    while y * y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

maxdiv = 0
res = 0

for i in range(1, N):
    g = gcd(N, i)
    if len(factorize(g)) >= K:
        d = len(divisor(i))
        if maxdiv < d:
            res = i
            maxdiv = d

print(res)
0