結果

問題 No.811 約数の個数の最大化
ユーザー MineMine
提出日時 2020-09-09 17:43:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 9,812 KB
最終ジャッジ日時 2023-08-22 04:34:34
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,712 KB
testcase_01 AC 21 ms
8,616 KB
testcase_02 AC 166 ms
9,524 KB
testcase_03 AC 19 ms
8,800 KB
testcase_04 AC 19 ms
8,632 KB
testcase_05 AC 22 ms
8,756 KB
testcase_06 AC 32 ms
8,780 KB
testcase_07 AC 35 ms
8,764 KB
testcase_08 AC 92 ms
9,296 KB
testcase_09 AC 93 ms
9,276 KB
testcase_10 AC 71 ms
8,912 KB
testcase_11 AC 125 ms
9,364 KB
testcase_12 AC 58 ms
9,024 KB
testcase_13 AC 233 ms
9,812 KB
testcase_14 AC 164 ms
9,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import math

def Sieve_of_Eratosthenes(maxA):
    lst = [-1]*(maxA+1)
    lst[0] = 0
    lst[1] = 1
    for i in range(2, maxA+1):
        if lst[i] == -1:
            for g in range(i, maxA+1, i):
                if lst[g] == -1:
                    lst[g] = i
    return lst

def factorization(n):
    d = defaultdict(int)
    now = n
    while True:
        if now == lst[now]:
            if now != 1:
                d[now] += 1
            break
        r = lst[now]
        while now % r == 0:
            now //= r
            d[r] += 1
    return d

num = 0
MAX = 0
n, k = map(int, input().split())
lst = Sieve_of_Eratosthenes(n)
for i in range(1, n):
    common = sum(factorization(math.gcd(i, n)).values())
    if common >= k:
        v = factorization(i).values()
        ans = 1
        for g in v:
            ans *= (g+1)
        if num < ans:
            num = ans
            MAX = max(MAX, i)

print(MAX)
0