結果

問題 No.811 約数の個数の最大化
ユーザー O2MTO2MT
提出日時 2020-08-19 00:25:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 724 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 08:04:49
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 95 ms
11,008 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 AC 25 ms
10,880 KB
testcase_05 AC 29 ms
10,880 KB
testcase_06 AC 34 ms
10,880 KB
testcase_07 AC 38 ms
10,880 KB
testcase_08 AC 62 ms
10,880 KB
testcase_09 AC 149 ms
10,880 KB
testcase_10 AC 59 ms
11,008 KB
testcase_11 AC 88 ms
11,008 KB
testcase_12 AC 47 ms
10,880 KB
testcase_13 AC 724 ms
10,880 KB
testcase_14 AC 99 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
#素因数列挙
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

#約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

ans,count = 0,0
for i in range(N-1,0,-1):
  GCD = gcd(N,i)
  Pr_GCD = prime_factorize(GCD)
  if len(Pr_GCD) >= K:
    lenGcd = len(make_divisors(i))
    if lenGcd >= count:
      count = lenGcd
      ans = i
  
print(ans)
0