結果
問題 | No.847 Divisors of Power |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:15:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 1,532 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,720 KB |
実行使用メモリ | 76,200 KB |
最終ジャッジ日時 | 2025-03-20 21:16:23 |
合計ジャッジ時間 | 2,555 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
def factorize(n):factors = []if n == 1:return factorsi = 2while i * i <= n:if n % i == 0:cnt = 0while n % i == 0:cnt += 1n = n // ifactors.append((i, cnt))i += 1if n > 1:factors.append((n, 1))return factorsdef count_divisors(primes, M, index, current_prod):if current_prod > M:return 0if index == len(primes):return 1total = 0p, e_max = primes[index]quotient = M // current_prodif quotient == 0:return 0# Compute maximum exponent a such that p^a <= quotientmax_power = 0current_p = 1while True:if current_p > quotient:breakmax_power += 1current_p *= pmax_power -= 1max_a = min(max_power, e_max)# Now iterate through possible exponentscurrent_p = 1for a in range(0, max_a + 1):new_prod = current_prod * current_pif new_prod > M:breaktotal += count_divisors(primes, M, index + 1, new_prod)current_p *= preturn totaldef main():import sysinput_line = sys.stdin.readline()N, K, M = map(int, input_line.strip().split())if N == 1:print(1 if M >= 1 else 0)returnfactors = factorize(N)primes_K = [(p, e * K) for (p, e) in factors]primes_K.sort()result = count_divisors(primes_K, M, 0, 1)print(result)if __name__ == "__main__":main()