結果

問題 No.847 Divisors of Power
ユーザー tpyneriver
提出日時 2019-08-10 20:45:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 909 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 283,920 KB
最終ジャッジ日時 2024-10-07 03:10:58
合計ジャッジ時間 5,624 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 23 TLE * 2 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush as hp, heappop as hpp
def prf(m):
    pf = {}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf

def calc(Num, L):
    res = 1
    for n, l in zip(Num, L):
        res *= pow(l, n)
    return res

N, K, M = map(int, input().split())
Pf = prf(N)
if not Pf:
    print(1)
else:
    Pkey, Pval = map(list, zip(*Pf.items()))
    pl = len(Pkey)
    
    cnt = 0
    Q = [(1, tuple(0 for _ in range(pl)))]
    used = set()
    while Q:
        x, pp = hpp(Q)
        if x > M:
            break
        if any(a*K < b for a, b in zip(Pval, pp)) or pp in used:
            continue
        used.add(pp)
        cnt += 1
        for i in range(pl):
            lp = list(pp)
            lp[i] += 1
            hp(Q, (calc(lp, Pkey), tuple(lp)))
    
    print(cnt)           
0