結果

問題 No.847 Divisors of Power
ユーザー hrbt__hrbt__
提出日時 2019-07-23 19:41:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-16 09:48:22
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
from math import log

ans = 1


def p_factor(n):
    p_cnt = {}
    for i in range(2, int(n**0.5) + 2):
        while n % i == 0:
            n //= i
            p_cnt[i] = p_cnt[i] + 1 if i in p_cnt else 1
    if n > 1:
        p_cnt[n] = p_cnt[n] + 1 if n in p_cnt else 1
    return p_cnt


def dfs(p_cnt, r, k):
    global ans
    if k < 0:
        ans += 1
        return
    a, e = p_cnt[k]
    for i in range(e + 1):
        q = r // a**i
        if q > 0:
            dfs(p_cnt, q, k - 1)


def main():
    n, k, m = map(int, input().split())
    p_cnt = p_factor(n)
    for i, x in p_cnt.items():
        p_cnt[i] = min(k * x, int(log(m, i)))
    dfs(sorted(p_cnt.items()), m, len(p_cnt) - 1)
    print(ans - 1)


if __name__ == '__main__':
    main()
0