Problem:
 Score : 400 points    Problem Statement You are given positive integers N and M .  How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M ? Find the count modulo 10^9+7 .  Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i'' .      Constraints  All values in input are integers.  1 \leq N \leq 10^5  1 \leq M \leq 10^9         Input Input is given from Standard Input in the following format:  N  M       Output Print the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7 .        Sample Input 1 2 6      Sample Output 1 4  Four sequences satisfy the condition: \{a_1, a_2\} = \{1, 6\}, \{2, 3\}, \{3, 2\} and \{6, 1\} .       Sample Input 2 3 12      Sample Output 2 18       Sample Input 3 100000 1000000000      Sample Output 3 957870001

Solution (Python):
from collections import Counter

N,M=map(int,input().split())
mod = 10**9+7

factorial=[1 for i in range(10**6)]
for i in range(2,10**6):
    factorial[i] = factorial[i-1]*i % mod

def comb(n,k):
    return (factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod))%mod

def factorize(n):
    out=[]
    i = 2
    while 1:
        if n%i==0:
            out.append(i)
            n //= i
        else:
            i += 1
        if n == 1:break
        if i > int(n**.5+3):
            out.append(n)
            break
    
    return out
  
c = Counter(factorize(M))

ans = 1
for k in c.keys():
  ans *= comb(c[k]+N-1,N-1)
  ans %= mod
  
print(ans)

Solution (Python):
import math
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
ans = 1
a,b = map(int,input().split())
l = fac(b)
for i in l:
  ans *= cmb(i[1]+a-1,a-1)
  ans = ans % (10**9 + 7)
if b == 1:
  print(1)
else:
  print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6
mod = 10 ** 9 + 7 





		

lim = 2*10**5   
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod


fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod



def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr


N, M = MAP()
if M == 1:
	print(1)
	exit()

arr = factorization(M)
ans = 1
for g, n in arr:
	ans *= C(N-1+n, n)
	ans %= mod

print(ans)

Solution (Python):
def factorize(n):
    '''
    素因数分解をする。
    タプルの配列にしようと思ったけど、逐次割り算する過程で次数を増やせないじゃん。
    二重配列?
    dictにしよう。
    '''
    if n == 1:
        raise('n >= 2')
    
    factor = {}
    div = 2
    while True:
        if div * div > n:
            factor[n] = factor.get(n, 0) + 1
            return factor

        if n % div == 0:
            n //= div
            factor[div] = factor.get(div, 0) + 1
        else:
            div += 1




n, m = list(map(int, input().split()))

if m == 1:
    print(1)
    exit()

factor = factorize(m)


max_len = n + 100  
mod = 10**9 + 7


def modinv(x):
    '''
    xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
    Python標準のpowは割った余りを出すことも可能。
    '''
    return pow(x, mod-2, mod)





modinv_table = [-1] * (max_len + 1)
modinv_table[0] = None  
factori_table = [1] * (max_len + 1)
factori_inv_table = [1] * (max_len + 1)
for i in range(1, max_len + 1):
    factori_table[i] = factori_table[i-1] * (i) % mod

modinv_table[1] = 1
for i in range(2, max_len + 1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
    factori_inv_table[i] = factori_inv_table[i-1] * modinv_table[i] % mod


def binomial_coefficients(n, k):
    '''
    n! / (k! * (n-k)! )
    0 <= k <= nを満たさないときは変な値を返してしまうので、先にNoneを返すことにする。
    場合によっては0のほうが適切かもしれない。
    '''
    if not 0 <= k <= n:
        return None
    return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod


ans = 1
mod = 10**9 + 7
for prime, power in factor.items():
    
    ans *= binomial_coefficients(n+power-1, power)
    ans %= mod

print(ans)

Solution (Python):
n,m=map(int,input().split())
mod=10**9+7



def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] 
g2=[1,1] 
inverse=[0,1]
for i in range(2,min(2*10**5,n+m)+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)



def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr




if m==1:
  print(1)
  exit()
ary=factorization(m)
ans=1
for x,y in ary:
  ans*=cmb(n-1+y,y,mod)
  ans%=mod
print(ans)

Solution (Python):
n, m = map(int, input().split())
mod = 10**9 + 7

def fctr1(n):
    f = []
    c = 0
    r = int(n**0.5)
    for i in range(2, r+2):
        while n % i == 0:
            c += 1
            n = n//i
        if c != 0:
            f.append([i, c])
            c = 0
    if n != 1:
        f.append([n, 1])
    return f

def comb(n, r):
    res = 1
    for i in range(1, r+1):
        res = res*(n-i+1) % mod
        res = res*pow(i, mod-2, mod) % mod
    return res

prime_count = fctr1(m)

ans = 1
for p, e in prime_count:
    ans *= comb(e+n-1, e)
    ans %= mod
print(ans)

Solution (Python):
from collections import defaultdict


def comb(n, k, mod=10 ** 9 + 7):
    denominator = 1
    numerator = 1
    for i in range(1, k + 1):
        denominator = denominator * i % mod
    for i in range(n - k + 1, n + 1):
        numerator = numerator * i % mod
    return numerator * pow(denominator, mod - 2, mod) % mod


def main():
    n, m = map(int, input().split())
    factorization = defaultdict(int)
    while not m % 2:
        factorization[2] += 1
        m //= 2
    f = 3
    while f * f <= m:
        if not m % f:
            factorization[f] += 1
            m //= f
        else:
            f += 2
    if m != 1:
        factorization[m] += 1
    ans = 1
    mod = 10 ** 9 + 7
    for _, c in factorization.items():
        ans *= comb(c + n - 1, c, mod)
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N,M=map(int, input().split())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 2*10 ** 5  
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


F = factorization(M)

if N==1:
    print(1)
    exit()
if M==1:
    print(1)
    exit()
ans=1
for l in F:
    ans*=cmb(N-1+l[1], l[1], p)
    ans%=p

print(ans)

Solution (Python):
mod=10**9+7


from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n,m=map(int,input().split())


if m==1:
    print(1)
    exit()


x=factorization(m)

ans=1

for i in x:
    ans*=cmb(n+i[1]-1,i[1])
    ans%=mod


print(ans)

Solution (Python):
n,m=map(int,input().split())
p=10**9+7
w=[]
M=m
i=2
cnt=0

def f(n,k,p):
    if k==0:
        return 1
    elif k%2==0:
        return (f(n,k//2,p)**2)%p
    else:
        return (n*f(n,k-1,p))%p

while i*i<=M:
    if m%i==0:
        cnt+=1
        m=m//i
    else:
        if cnt>=1:
            w.append(cnt)
        cnt=0
        i+=1
if m>1:
    w.append(1)

ans=1
for x in w:
    a=1
    for i in range(x):
        a=(a*(n+i))%p
    b=1
    for i in range(x):
        b=(b*(i+1))%p

    ans=(ans*a*f(b,p-2,p))%p
print(ans%p)

Solution (Python):
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

n = 2*pow(10,5)+10
MOD = pow(10,9)+7

fac = [-1]*(n+1); fac[0] = 1; fac[1] = 1 
finv = [-1]*(n+1); finv[0] = 1; finv[1] = 1 
inv = [-1]*(n+1); inv[0] = 0; inv[1] = 1 
for i in range(2,n+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1: 
        arr.append([temp, 1])
 
    if arr==[]: 
        arr.append([n, 1])
 
    return arr


N,M = map(int,input().split())
A = factorization(M)

ans = 1
for X in A:
  if X == [1,1]:
    continue
  k = X[1]
  temp = cmb(k+N-1,k,MOD)
  ans = ans*temp%MOD
print(ans%MOD)

Solution (Python):
def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
mod = 10**9+7 
size = 10**6 
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 
 
for i in range( 2, size + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)
 
    if temp!=1:
        arr.append(1)
 
    return arr
 
N, M = map(int,input().split())
L = factorization(M)
 
ans = 1
 
for i in L:
    ans *= nCr(i+N-1,N-1,mod)
    ans %= mod
 
print(ans)

Solution (Python):
class Factorials:
    def __init__(self, n=10**6, mod=10**9 + 7):
        self.mod = mod

        
        self.fac = [1]
        num = 1
        for i in range(1, n+1):
            num *= i
            num %= mod
            self.fac.append(num)

        
        num = pow(num, mod-2, mod)
        self.rec = [1 for i in range(n+1)]
        self.rec[n] = num
        for i in range(n-1, 0, -1):
            num *= i + 1
            num %= mod
            self.rec[i] = num

    
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod
    
    
    def perm(self, n, r):
        return self.fac[n] * self.rec[n-r] % self.mod

    
    def fact(self, n):
        return self.fac[n]

def main():
    mod = 10**9 + 7
    n, m = map(int, input().split())

    if m == 1:
        print(1)
        exit()

    factors = []
    for i in range(2, m+1):
        if i * i > m:
            if m > 1:
                factors.append(1)
            break

        if m % i == 0:
            num = 1
            m //= i
            while m % i == 0:
                num += 1
                m //= i
            factors.append(num)

    fct = Factorials(n=n+max(factors), mod=mod)

    ans = 1
    for i in factors:
        ans *= fct.comb(n+i-1, i)
        ans %= mod

    print(ans)

main()

Solution (Python):
max_n=10**6
mod=10**9+7

frac=[1]
for i in range(1,max_n+1):
  frac.append((frac[-1]*i)%mod)

inv=[1,1]
inv_frac=[1,1]
for i in range(2,max_n):
  inv.append((mod-inv[mod%i]*(mod//i))%mod)
  inv_frac.append((inv_frac[-1]*inv[-1])%mod)
  
def perm(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[m-n])%mod

def comb(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod




n,m=map(int,input().split())
l=[]
for i in range(2,int(m**0.5)+1):
  if m%i==0:
    c=0
    while m%i==0:
      m//=i
      c+=1
    l.append(c)
if m!=1:
  l.append(1)

r=1
for i in l:
  r=(r*comb(n+i-1,i))%mod
print(r)

Solution (Python):

def prime_decomposition(n):
	i = 2
	table = []
	while i * i <= n:
		while n % i == 0:
			n //= i
			table.append(i)
		i += 1
	if n > 1:
		table.append(n)
	return table

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


def combination(n, r, mod=10**9+7):
	r = min(r, n-r)
	res = 1
	for i in range(r):
		res = res * (n - i) * modinv(i+1, mod) % mod
	return res


def H(n, r, mod=10**9+7):
	return combination(n+r-1, r, mod)

from collections import defaultdict
N, M = map(int, input().split())
prime_table = prime_decomposition(M)
dic = defaultdict(int) 
for p in prime_table:
    dic[p] += 1

ans=1
for p, b in dic.items():
	ans *= H(N, b, mod=10**9+7)
print(ans%(10**9+7))

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def primeFactorization(n):
    ans = []
    temp = n
    while temp%2 == 0:
        ans.append(2)
        temp //= 2
    for i in range(3, int(n**0.5)+1, 2):
        while temp%i == 0:
            ans.append(i)
            temp //= i
    if temp > 1:
        ans.append(temp)
    return collections.Counter(ans)

def combMod(n, r, p):
    numer = 1
    denom = 1
    for i in range(1, r+1):
        numer = numer * (n-r+i) % p
        denom = denom * i % p
    return numer * pow(denom, p-2, p) % p

def resolve():
    N, M = LI()

    pf = primeFactorization(M)
    
    ans = 1
    for i in pf.values():
        ans *= combMod(i + N - 1, i, MOD)        
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
MAX = 10**6
MOD = 10**9+7

fac = [0] * (MAX+1)
finv = [0] * (MAX+1)
inv = [0] * (MAX+1)

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


def prime_factorize(n):
    table = {}
    while n % 2 == 0:
        table[2] = table.get(2, 0) + 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            table[f] = table.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        table[n] = table.get(n, 0) + 1
    return table


if __name__ == '__main__':
    n, m = map(int, input().split())
    comb_init()
    prime_factor = prime_factorize(m)
    res = 1
    for v in prime_factor.values():
        res *= comb(v+n-1, n-1)
        res %= MOD
    print(res)

Solution (Python):
from collections import defaultdict
import math
def factorize(n):
    i = 2
    factors = defaultdict(int)
    while i**2 <= n:
        if n % i != 0:
            i += 1
            continue

        while n % i == 0:
            n //= i
            factors[i] += 1
        i += 1

    if n != 1:
        factors[n] += 1

    return factors

def C(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

N, M = map(int, input().split())
factors = factorize(M)


ans = 1
for key, val in factors.items():
    ans *= C(N + val - 1, val)

MOD = 10**9 + 7
print(ans % MOD)

Solution (Python):
from math import floor, sqrt
from collections import defaultdict
N,M = map(int,input().split())
d = defaultdict(int)
for i in range(2, floor(sqrt(M))+1):
    while M % i == 0:
        d[i] += 1
        M //= i
if M != 1:
    d[M] += 1
def comb(n,k):
    if k == 0:
        return 1
    return comb(n-1,k-1) * n // k
ans = 1
for e in d.values():
    ans *= comb(N+e-1, e)
print(ans % (10**9+7))

Solution (Python):
N,M = map(int,input().split())
ans = int(M**0.5+10)*[N-1]
mod = 10**9+7
p = 2
O = M

while p<=O**0.5:
  if M%p == 0:
    M = M//p
    ans[p] += 1
  else:
    p+=1
    
if M!=1:
  ans[-1]+=1

out = 1
for r in ans:
  hoge = 1
  for i in range(min(N-1,r-N+1)):
    hoge*=r-i
    hoge//=i+1
  out*=hoge
  out%=mod

print(out)

Solution (Python):
N,M=map(int,input().split())
import math


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from collections import Counter
L=prime_factorize(M)
c=Counter(L)
k=[]
for v in c.values():
  k.append(v)
mod=10**9+7
P=[1 for i in range(10**6+1)]
for i in range(10**6):
  P[i+1]=P[i]*(i+1)%mod


def comb(a,b):
  return P[a]*pow(P[a-b],mod-2,mod)*pow(P[b],mod-2,mod)%mod
ans=1
for i in range(len(k)):
  ans*=comb(N+k[i]-1,k[i])
  ans%=mod
print(ans)

Solution (Python):
import math



def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

mod = 10**9 + 7
N = 10**6


g1 = [1, 1]

g2 = [1, 1]

inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)




def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root + 1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


N, M = map(int, input().split())

prime = prime_fact(M)
ans = 1



for v in prime.values():
    ans *= cmb(N + v - 1, v, mod)
    ans %= mod
print(ans)

Solution (Python):
def factorize(n):
    b = 2
    fct = [(1,1)]
    while b * b <= n:
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
        b = b + 1
    if n > 1:
        fct.append((n,1))
    return fct

nmax = 10**6
mod = 10**9+7
fac = [1]*nmax
finv = [1]*nmax
inv = [1]*nmax
def ncr_pre():
    for i in range(2,nmax):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i] %mod

def ncr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n]* (finv[r] * finv[n-r] %mod) %mod

ncr_pre()
n,m = map(int,input().split())
ls = factorize(m)
tmp = 1
for num,cnt in ls:
    if num==1:continue

    tmp=tmp*ncr(n+cnt-1,cnt) %mod
print(tmp)

Solution (Python):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()



def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def combination_mod_initialize(n, MOD=10**9+7):
    fac = [1]*(n+1)
    inv = [1]*(n+1)
    for i in range(1, n+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, MOD-2, MOD) % MOD
    return fac, inv


def combination_mod(n, r, fac, inv, mod=10**9+7):
    return fac[n] * inv[r] * inv[n-r]


def main():
    N, M = NMI()
    PD = prime_fact(M)
    ans = 1
    fac, inv = combination_mod_initialize(10**6, MOD)

    for x in list(PD.values()):
        ans = ans * combination_mod(N+x-1, N-1, fac, inv) % MOD

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()



def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def combination_mod_initialize(n, MOD=10**9+7):
    fac = [1]*(n+1)
    inv = [1]*(n+1)
    for i in range(1, n+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, -1, MOD) % MOD
    return fac, inv


def combination_mod(n, r, fac, inv, mod=10**9+7):
    return fac[n] * inv[r] * inv[n-r]


def main():
    N, M = NMI()
    PD = prime_fact(M)
    ans = 1
    fac, inv = combination_mod_initialize(10**6, MOD)

    for x in list(PD.values()):
        ans = ans * combination_mod(N+x-1, N-1, fac, inv) % MOD

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict


def prime_factor(n):
    
    d = defaultdict(int)
    for i in range(2, n + 1):
        if i * i > n:
            break

        while n % i == 0:
            d[i] += 1
            n //= i

    if n != 1:
        d[n] += 1

    return d


MAX = 2 * 10 ** 5 + 10
MOD = 10 ** 9 + 7


fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1


inv = [0] * (MAX + 1)
inv[1] = 1


finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1

for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD


def comb_rep(n, k):
    return comb(n + k - 1, n - 1)


N, M = map(int, input().split())
primes = prime_factor(M)
res = 1
for k in primes.values():
    res *= comb_rep(N, k)
    res %= MOD

print(res)

Solution (Python):
def prime_factorization(n):
    """
    nを素因数分解
    :param n:
    :return:素因数分解結果 [(素数S1, count S1),(素数S2, count S2), ...]

    """
    from math import sqrt
    if (n == 0): return []
    if (n == 1): return [(1, 1)]

    res = []
    for i in range(2, int(sqrt(n)) + 1):
        if n == 1: break
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt > 0:
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))

    return res


class ModFactorial:
    """
    階乗, 組み合わせ, 順列の計算
    """

    def __init__(self, n, MOD=10 ** 9 + 7):
        """

        :param n: 最大の要素数.
        :param MOD:
        """
        kaijo = [0] * (n + 10)
        gyaku = [0] * (n + 10)

        kaijo[0] = 1
        kaijo[1] = 1
        for i in range(2, len(kaijo)):
            kaijo[i] = (i * kaijo[i - 1]) % MOD
        gyaku[0] = 1
        gyaku[1] = 1
        for i in range(2, len(gyaku)):
            gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
        self.kaijo = kaijo
        self.gyaku = gyaku
        self.MOD = MOD

    def nCm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD

    def nPm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD

    def factorial(self, n):
        return self.kaijo[n]


N, M = [int(_) for _ in input().split()]
if M == 1:
    print(1)
    exit()

primes = [v for _, v in prime_factorization(M)]

MOD = 10 ** 9 + 7
mf = ModFactorial(max(primes) + 1 + N, MOD)

ans = 1
for cnt in primes:
    ans = ans * mf.nCm(cnt + N - 1, N - 1)
    ans = ans % MOD
print(ans)

Solution (Python):
N, M = map(int, input().split())
MOD = 10**9+7
MAX = 10**6
if M==1:
    print(1)
    exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            
            arr.append(cnt)
    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)

    return arr

arr = factorization(M)
def COMinit():
    """
    逆元テーブルをつくる前処理
    計算量はO(n)
    1 <= k <= n <= 1e7程度
    p: 素数
    """
    fac = [0]*MAX
    finv = [0]*MAX
    inv = [0]*MAX

    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[0], inv[1] = 1, 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv


def comb(n, k):
    """
    nCk mod MODを求める.
    この部分はO(1)
    """
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return int(fac[n] * (finv[k] * finv[n-k] % MOD) % MOD)

def perm(n, k):
    """
    nPk mod MOD
    """
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return int((fac[n] * finv[n-k])%MOD)
fac, finv, inv = COMinit()

ans = 1
for k in arr:
    ans *= comb(N+k-1, k)
    ans %= MOD
print(ans)

Solution (Python):
import sys









MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def factorization(n):
    prime = []
    num = n
    p = 2
    while p * p <= n:
        cnt = 0
        while num % p == 0:
            cnt += 1
            num //= p
        prime.append((p, cnt))
        p += 1
    if num != 1:
        prime.append((num, 1))
    if not prime:
        prime.append((n, 1))
         
    return prime

def nCr(n, r, mod):
    a, b = 1, 1
    for i in range(r):
        a = a * (n - i) % mod
        b = b * (i + 1) % mod
    
    return a * pow(b, mod - 2, mod) % mod

def Main():
    n, m = read_ints()
    prime = factorization(m)
    ans = 1
    for p, num in prime:
        ans *= nCr(num + n - 1, num, MOD)
        ans %= MOD
    
    if m == 1:
        print(1)
    else:
        print(ans)

if __name__ == '__main__':
    Main()

Solution (Python):

N,M=map(int,input().split())
p=10**9+7
L=10**5*3
f,inv,finv=[0]*(L+1),[0]*(L+1),[0]*(L+1)

def factorization(N):
    res=[]
    for i in range(2,int(N**(1/2))+2):
        if not N%i:
            r=0
            while not N%i:
                N//=i
                r+=1
            res.append((i,r))
    if N>1:
        res.append((N,1))
    return res

def nCr_init(L,p):
    for i in range(L+1):
        if i<=1:
            f[i],finv[i],inv[i]=1,1,1
        else:
            f[i]=(f[i-1]*i)%p
            inv[i]=(p-inv[p%i]*(p//i))%p
            finv[i]=(finv[i-1]*inv[i])%p

def nCr(n,r,p):
    if 0<=r<=n and 0<=n:
        return (f[n]*finv[n-r]*finv[r])%p
    else:
        return 0

nCr_init(L,p)
p_list=factorization(M)
res=1
for a,r in p_list:
    res=(res*nCr(r+N-1,r,p))%p
print(res)

Solution (Python):
n,m = map(int,input().split())
if(m==1):
    print(1)
    exit()

mod = 10**9+7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5//1)+1 ):
        if(temp%i == 0):
            count=0
            while( temp%i == 0):
                count += 1
                temp = temp // i
            arr.append([i, count])

    if(temp != 1):
        arr.append([temp, 1])

    if(arr == []):
        arr.append([n, 1])

    return arr

max_n = 2 * 10**5
fac, finv, inv = [0]*max_n, [0]*max_n, [0]*max_n

def comInit(max_n):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max_n):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max_n)


def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

arr = factorization(m)

ans = 1
for _,k in arr:
    ans *= com(n+k-1, k)
    ans %= mod

print(ans)

Solution (Python):
def factorize(n):
    factor = []
    if n % 2 == 0:
        f = [2, 1]
        n //= 2
        while n % 2 == 0:
            n //= 2
            f[1] += 1
        factor.append(f)
    k = 3
    while k * k <= n:
        if n % k == 0:
            f = [k, 1]
            n //= k
            while n % k == 0:
                n //= k
                f[1] += 1
            factor.append(f)
        k += 2
    if n != 1:
        factor.append([n, 1])
    return factor

def factorial(n, mod):
    fac = [0] * (n + 1)
    inv = [0] * (n + 1)
    fac[0], inv[0] = 1, 1
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % mod
        inv[i] = inverse(fac[i], mod)
    return fac, inv

def inverse(a, mod):
    a %= mod 
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod 

n, m = map(int, input().split())
if m == 1:
    print(1)
    quit()
mod = 10 ** 9 + 7
f = factorize(m)
max_k = max(i for _, i in f)
fac, inv = factorial(n + max_k - 1, mod)
ans = 1
for _, k in f:
    ans = ans * fac[n + k - 1] % mod * inv[n - 1] % mod * inv[k] % mod
print(ans)