結果
問題 |
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 factors i = 2 while i * i <= n: if n % i == 0: cnt = 0 while n % i == 0: cnt += 1 n = n // i factors.append((i, cnt)) i += 1 if n > 1: factors.append((n, 1)) return factors def count_divisors(primes, M, index, current_prod): if current_prod > M: return 0 if index == len(primes): return 1 total = 0 p, e_max = primes[index] quotient = M // current_prod if quotient == 0: return 0 # Compute maximum exponent a such that p^a <= quotient max_power = 0 current_p = 1 while True: if current_p > quotient: break max_power += 1 current_p *= p max_power -= 1 max_a = min(max_power, e_max) # Now iterate through possible exponents current_p = 1 for a in range(0, max_a + 1): new_prod = current_prod * current_p if new_prod > M: break total += count_divisors(primes, M, index + 1, new_prod) current_p *= p return total def main(): import sys input_line = sys.stdin.readline() N, K, M = map(int, input_line.strip().split()) if N == 1: print(1 if M >= 1 else 0) return factors = 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()