結果

問題 No.847 Divisors of Power
ユーザー mkawa2mkawa2
提出日時 2019-07-05 22:31:20
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,054 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 263,384 KB
最終ジャッジ日時 2024-04-16 07:48:40
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,068 KB
testcase_01 AC 48 ms
54,056 KB
testcase_02 AC 48 ms
59,168 KB
testcase_03 AC 43 ms
53,468 KB
testcase_04 AC 59 ms
65,588 KB
testcase_05 AC 47 ms
59,396 KB
testcase_06 AC 47 ms
60,028 KB
testcase_07 AC 43 ms
53,340 KB
testcase_08 AC 47 ms
58,424 KB
testcase_09 AC 48 ms
60,232 KB
testcase_10 AC 52 ms
62,116 KB
testcase_11 AC 69 ms
70,048 KB
testcase_12 AC 44 ms
53,940 KB
testcase_13 AC 69 ms
69,448 KB
testcase_14 AC 60 ms
65,660 KB
testcase_15 AC 1,805 ms
240,576 KB
testcase_16 AC 44 ms
59,132 KB
testcase_17 AC 47 ms
59,600 KB
testcase_18 AC 76 ms
72,744 KB
testcase_19 AC 106 ms
77,108 KB
testcase_20 AC 45 ms
58,032 KB
testcase_21 AC 552 ms
122,956 KB
testcase_22 AC 46 ms
58,220 KB
testcase_23 AC 44 ms
58,908 KB
testcase_24 TLE -
testcase_25 AC 47 ms
58,876 KB
testcase_26 AC 43 ms
53,152 KB
testcase_27 AC 45 ms
58,600 KB
testcase_28 AC 44 ms
54,128 KB
testcase_29 AC 42 ms
53,808 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()
    used.add(tuple(a))
    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
            ta = tuple(na)
            if ta in used: continue
            heappush(hp, [ny] + na)
            used.add(ta)
        cnt += 1
    print(cnt)

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