結果

問題 No.811 約数の個数の最大化
ユーザー roarisroaris
提出日時 2019-08-24 09:44:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-21 16:05:14
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 69 ms
66,816 KB
testcase_02 AC 206 ms
77,696 KB
testcase_03 AC 42 ms
52,480 KB
testcase_04 AC 49 ms
59,264 KB
testcase_05 AC 75 ms
70,272 KB
testcase_06 AC 146 ms
77,516 KB
testcase_07 AC 94 ms
76,384 KB
testcase_08 AC 227 ms
77,680 KB
testcase_09 AC 135 ms
76,800 KB
testcase_10 AC 132 ms
77,088 KB
testcase_11 AC 119 ms
76,800 KB
testcase_12 AC 132 ms
76,644 KB
testcase_13 AC 260 ms
76,800 KB
testcase_14 AC 209 ms
77,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factorize(n):
    factors = []
    
    for div in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n % div == 0:
            n //= div
            cnt += 1
        
        if cnt > 0:
            factors.append((div, cnt))
    
    if n > 1:
        factors.append((n, 1))
    
    return factors
    
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
N, K = map(int, input().split())
prev_i_cnt = 0

for i in range(2, N):
    G = gcd(i, N)
    G_factors = factorize(G)
    
    if sum([G_factors_i[1] for G_factors_i in G_factors]) >= K:
        i_factors = factorize(i)
        i_cnt = 1
        
        for _, c in i_factors:
            i_cnt *= (c + 1)
    
        if i_cnt > prev_i_cnt:
            ans = i
            prev_i_cnt = i_cnt

print(ans)
0