結果

問題 No.847 Divisors of Power
ユーザー mkawa2mkawa2
提出日時 2019-07-05 22:37:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,616 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 72,244 KB
最終ジャッジ日時 2024-04-16 07:51:30
合計ジャッジ時間 5,193 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,752 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 33 ms
10,880 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 34 ms
10,880 KB
testcase_05 AC 33 ms
10,752 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 33 ms
10,880 KB
testcase_09 AC 32 ms
11,008 KB
testcase_10 AC 32 ms
10,752 KB
testcase_11 AC 33 ms
10,880 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 33 ms
10,880 KB
testcase_14 AC 33 ms
10,880 KB
testcase_15 AC 1,244 ms
52,340 KB
testcase_16 AC 33 ms
10,752 KB
testcase_17 AC 33 ms
10,880 KB
testcase_18 AC 35 ms
11,136 KB
testcase_19 AC 45 ms
11,904 KB
testcase_20 AC 33 ms
10,880 KB
testcase_21 AC 319 ms
26,456 KB
testcase_22 AC 33 ms
11,008 KB
testcase_23 AC 35 ms
10,880 KB
testcase_24 AC 1,616 ms
72,244 KB
testcase_25 AC 32 ms
10,752 KB
testcase_26 AC 32 ms
10,752 KB
testcase_27 AC 35 ms
10,880 KB
testcase_28 AC 32 ms
10,880 KB
testcase_29 AC 32 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

def f(n, k, m):
    if n == 1:
        print(1)
        exit()
    tei = []
    sis = []
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    if cnt:
        tei = [2]
        sis = [cnt * k]
    i = 3
    while i ** 2 <= n:
        cnt = 0
        while n % i == 0:
            cnt += 1
            n //= i
        if cnt:
            tei += [i]
            sis += [cnt * k]
        i += 2
    if n > 1:
        tei += [n]
        sis += [k]
    # print(sis)
    # print(tei)
    kos = len(tei)
    hp = []
    a = [0] * kos
    heappush(hp, [1] + a)
    used = set()
    cnt = 0
    while 1:
        y, *a = heappop(hp)
        if y > m: break
        for i in range(kos):
            if a[i] == sis[i]: continue
            ny = y * tei[i]
            na = a[:]
            na[i] += 1
            if ny in used: continue
            heappush(hp, [ny] + na)
            used.add(ny)
        cnt += 1
    print(cnt)

n, k, m = map(int, input().split())
f(n, k, m)
0