Codey and Facto
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c9
Last updated
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c9
Last updated
Codey is very interested in facto, a concept he learned in the mathematics class last week.
If you are given an integer n
and an integer m
, a facto of n
and m
is an array of integers such that the product of every element in the array is n
, and the length of the array is m
.
For example, when , one of the facto is , as , and the array's length is . Other examples of facto for include , and .
Codey wants you to find the total number of unique facto that exist for the n
and m
modulo . Recall that a
modulo b
is the remainder of a
when divided by b
.
The first line contains two integers, n
and m
, where n
represents the number n
, and m
represents the number of facto.
Output the total number of unique facto for n
and m
modulo .
8
import math
MOD = 10**9 + 7
def fcm(m, n):
MOD = 10**9 + 7
def prime_factorize(x):
factors = {}
d = 2
while d * d <= x:
while x % d == 0:
factors[d] = factors.get(d, 0) + 1
x //= d
d += 1
if x > 1:
factors[x] = factors.get(x, 0) + 1
return factors
prime_factors = prime_factorize(m)
result = 1
for prime, exponent in prime_factors.items():
result *= math.comb(exponent + n - 1, n - 1)
result %= MOD
result *= pow(2, n - 1, MOD)
result %= MOD
return result
m, n = map(int, input().strip().split())
print(fcm(m, n))