結果

問題 No.811 約数の個数の最大化
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-04-15 16:57:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 627 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 11,948 KB
実行使用メモリ 11,768 KB
最終ジャッジ日時 2023-10-22 06:43:42
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,248 KB
testcase_01 AC 34 ms
10,324 KB
testcase_02 AC 149 ms
10,312 KB
testcase_03 AC 29 ms
10,244 KB
testcase_04 AC 28 ms
10,268 KB
testcase_05 AC 35 ms
10,324 KB
testcase_06 AC 40 ms
10,276 KB
testcase_07 AC 49 ms
10,328 KB
testcase_08 AC 93 ms
10,284 KB
testcase_09 AC 173 ms
10,572 KB
testcase_10 AC 81 ms
10,348 KB
testcase_11 AC 160 ms
10,308 KB
testcase_12 AC 66 ms
10,288 KB
testcase_13 AC 627 ms
11,768 KB
testcase_14 AC 164 ms
10,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math, collections, functools

@functools.lru_cache()
def prime_division(x):
    primes = []
    for i in range(2, math.ceil(math.sqrt(x)) + 1):
        while x % i == 0:
            primes.append(i)
            x //= i

    if x > 1:
        primes.append(x)
    return primes

@functools.lru_cache()
def count_factor(x):
    ans = 1
    for v in collections.Counter(prime_division(x)).values():
        ans *= v + 1
    return ans

@functools.lru_cache()
def gcd(a, b): # a < b
    while b % a != 0:
        a, b = b % a, a
    return a

if __name__ == '__main__':
    n, k = map(int, input().split())
    d = collections.defaultdict(list)
    for m in range(2, n):
        if len(prime_division(gcd(m, n))) >= k:
            d[count_factor(m)].append(m)
        
    print(min(d[max(d)]))

0