結果

問題 No.847 Divisors of Power
ユーザー mkawa2mkawa2
提出日時 2019-07-05 22:30:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,054 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 102,824 KB
最終ジャッジ日時 2024-04-16 07:48:14
合計ジャッジ時間 6,061 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 32 ms
10,752 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 32 ms
10,880 KB
testcase_10 AC 32 ms
10,752 KB
testcase_11 AC 33 ms
11,008 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 33 ms
11,008 KB
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 1,620 ms
79,256 KB
testcase_16 AC 32 ms
11,008 KB
testcase_17 AC 32 ms
10,880 KB
testcase_18 AC 36 ms
11,136 KB
testcase_19 AC 46 ms
12,288 KB
testcase_20 AC 33 ms
10,752 KB
testcase_21 AC 410 ms
34,168 KB
testcase_22 AC 33 ms
10,880 KB
testcase_23 AC 34 ms
10,880 KB
testcase_24 TLE -
testcase_25 AC 31 ms
10,880 KB
testcase_26 AC 32 ms
10,880 KB
testcase_27 AC 34 ms
10,880 KB
testcase_28 AC 31 ms
10,880 KB
testcase_29 AC 31 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()
    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