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



Sample input:
2 6


Sample output:
4

Submission status: Time Limit Exceeded

Solution code:
import math
import random
class Prime:
    seed_primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
    def is_prime(self,n):
        is_prime_common=self.is_prime_common(n)
        if is_prime_common is not None:return is_prime_common
        if n<2000000:return self.is_prime_brute_force(n)
        return self.is_prime_miller_rabin(n)
    def is_prime_common(self,n):
        if n==1:return False
        if n in Prime.seed_primes:return True
        if any(map(lambda x:n%x==0,self.seed_primes)):return False
    def is_prime_brute_force(self,n):
        for k in range(2,int(math.sqrt(n))+1):
            if n%k==0:return False
        return True
    def is_prime_miller_rabin(self,n):
        d=n-1
        while d&1==0:d>>=1
        witnesses=self.get_witnesses(n)
        for w in witnesses:
            y=pow(w,d,n)
            while d!=n-1and y!=1and y!=n-1:
                y=y*y%n
                d<<=1
            if y!=n-1and d&1==0:return False
        return True
    def get_witnesses(self,num):
        def _get_range(num):
            if num<2047:return 1
            if num<1373653:return 2
            if num<25326001:return 3
            if num<3215031751:return 4
            if num<2152302898747:return 5
            if num<3474749660383:return 6
            if num<341550071728321:return 7
            if num<3825123056546413051:return 9
            return 12
        return self.seed_primes[:_get_range(num)]
    def gcd(self,a,b):
        if a<b:return self.gcd(b,a)
        if b==0:return a
        while b:a,b=b,a%b
        return a
    @staticmethod
    def f(x,n,seed):
        p=Prime.seed_primes[seed%len(Prime.seed_primes)]
        return(p*x+seed)%n
    def find_factor(self,n,seed=1):
        if self.is_prime(n):return n
        x,y,d=2,2,1
        count=0
        while d==1:
            count+=1
            x=self.f(x,n,seed)
            y=self.f(self.f(y,n,seed),n,seed)
            d=self.gcd(abs(x-y),n)
        if d==n:
            return self.find_factor(n,seed+1)
        return self.find_factor(d)
    def find_factors(self,n):
        primes={}
        if self.is_prime(n):
            primes[n]=1
            return primes
        while n>1:
            factor=self.find_factor(n)
            primes.setdefault(factor,0)
            primes[factor]+=1
            n//=factor
        return primes
n,m=map(int,input().split())
a=1
for c in Prime().find_factors(m).values():
    a=a*(math.factorial(n+c-1)//(math.factorial(n-1)*math.factorial(c)))%(10**9+7)
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections

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


def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


def comb(n,k,p):
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % p
    b = factorial(k) % p
    c = factorial(n - k) % p
    return (a * power_func(b, p - 2, p) * power_func(c, p - 2, p)) % p


def power_func(a,b,p):
    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, p)
        return d * d % p
    if b % 2 == 1:
        return (a * power_func(a, b - 1, p)) % p

def m():
    ans = 1
    f = prime_factors(M)
    counts = collections.Counter(f)
    for k,v in counts.items():
        ans *= comb(v + N-1, N-1, MOD)
    return ans % MOD

print(m())

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import collections


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

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


def nPk(n, k):
    return math.factorial(n) // math.factorial(n-k)


def nCk(n, k):
    return math.factorial(n) // (math.factorial(n-k) * math.factorial(k))

def m():
    ans = 1
    f = prime_factors(M)
    counts = collections.Counter(f)
    l = len(f)
    for k,v in counts.items():
        ans *= nCk(v + N-1, N-1)
    return ans % MOD

print(m())

Submission status: Time Limit Exceeded

Solution code:
import math
def factoring(n,dict_count = {}):
    sup = math.floor(pow(n,1/2))
    n_new = n
    for i in range(2,sup + 1):
        if n % i == 0:
            n_new = n // i
            if i in dict_count:
                dict_count[i] += 1
            else:
                dict_count[i] = 1
            break
    if n == n_new:
        if n_new in dict_count:
            dict_count[n_new] += 1
        else:
            dict_count[n_new] = 1
        return sorted(list(dict_count.items()))
    return factoring(n_new,dict_count)

# 組み合わせ　n_C_r
import math
def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N,M = map(int,input().split())
if M == 1:
    print(1)
    exit()
ans = 1
for a,b in factoring(M):
    ans *= comb(b+N-1,b)
    ans %= 10**9 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n //= i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= numerator[k] % (10 ** 9 + 7)
    return result


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


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)

"""
n, m = [int(i) for i in input().split()]
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
count = 1
for i in range(len(divList)):
    count *= cmb(divList[i] + n - 1, min(divList[i], n-1))
    count %= 10 ** 9 + 7
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n //= i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


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


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)

"""
n, m = [int(i) for i in input().split()]
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
count = 1
for i in range(len(divList)):
    count *= cmb(divList[i] + n - 1, min(divList[i], n-1))
    count %= 10 ** 9 + 7
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math


def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n //= i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n;
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result;


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


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)

"""
n, m = [int(i) for i in input().split()]
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
count = 1
for i in range(len(divList)):
    count *= cmb(divList[i] + n - 1, min(divList[i], n-1))
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math
def ncr(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def factorize(n):
    d = {}
    m = 2
    while m*m <= n:
        if n%m == 0:
            d[m] = 0
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] = 1
    return d
count = 1
n,m = map(int,input().split())
mod = 10**9+7
b = factorize(m)
for i in b:
    count *= ncr(b[i]+n-1,b[i])%mod
print(count%mod)

Submission status: Time Limit Exceeded

Solution code:
def prf(n):
    pf = {}
    for i in range(2, int(n ** 1 / 2) + 1):
        while n % i == 0:
            if not i in pf:
                pf[i] = 0
            pf[i] += 1
            n //= i
    if n > 1:
        pf[n] = 1
    return pf

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

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

ans = 1
for i in prf(m).values():
    ans = ans * comb(n - 1 + i, i) % mod
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N,M = list(map(int,input().strip().split()))

i = 2
cnt = 0
ans = 1
while True:
  if M%i == 0:
    M = M//i
    cnt += 1
  else:
    ans *= math.factorial(N+cnt-1) // (math.factorial(N-1)*math.factorial(cnt))
    i += 1
    cnt = 0
    if M == 1:
      break
      
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as f

def prime_factors(n) :
    i = 2
    L = []
    while i ** 2 <= n :
        if n % i :
            i += 1
        else :
            n //= i
            L.append(i)
    if n > 1 :
        L.append(n)
    return L

def comb(n,r) :
    return f(n)//(f(r)*f(n-r))


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


P = prime_factors(M)
D = {}
for i in range(len(P)) :
    if P[i] not in D :
        D[P[i]] = 1
    else :
        D[P[i]] += 1

V = list(D.values())

ans = 1
for i in range(len(V)) :
    ans *= (comb(V[i]+N-1,N-1) % (10**9+7))
ans %= (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i ** 2 <= num:
        while num % i == 0:
            num //= i
            if i in prime_factor.keys():
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor


from math import factorial


def comb(n, r):
    return factorial(n) // (factorial(n-r) * factorial(r))


n, m = map(int, input().split())
r = 1
prime_fac = prime_factorize(m)
for v in prime_fac.values():
    r *= comb(v+n-1, v)
mod = 1000000000 + 7
print(r % mod)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections

N, M = input().strip().split(' ')
N, M = [int(N), int(M)]

#階乗
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#素因数分解
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

C = collections.Counter(prime_factors(M))

res = 1
for c in C.items():
    #print(c[0], c[1])
    res *= combinations_count((c[1] + N - 1), c[1])

print(res % (1000000007))

Submission status: Time Limit Exceeded

Solution code:
import collections

def factor(m):
  q = m
  r = []
  i = 2
  while q != 1:
    if q % i:
      i += 1
    else:
      r.append(i)
      q //= i
  return r

n, m = map(int, input().split())
p = 10 ** 9 + 7

r = factor(m)
v = collections.Counter(r)
c = 1
for value in v.values():
  temp = 1
  for i in range(value):
    temp *= value + n - 1 - i
  for i in range(value):
    temp //= i + 1
  temp %= p
  c = c * temp % p
print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict

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

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

pr = prime_factors(m)
di = {}
di = defaultdict(int)
for i in pr:
    while m % i == 0:
        m = m // i
        di[i] += 1
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 1
mod = 10 ** 9 + 7
for i in di:
    ans = ans * comb(di[i] + n - 1, di[i]) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

from math import sqrt
from itertools import permutations, combinations_with_replacement
import numpy as np

def num_div_set2(N):
    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て+1
    end = int(sqrt(N)) + 1
    for i in range(2, end+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

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

ans = 0
for comb in combinations_with_replacement(num_div_set2(M), N):
    if np.prod(comb) == M:
        ans = (ans + len(set(permutations(comb)))) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

X = {}
for i in range(2, M):
  if M == 1:
    break
  while True:
    if M % i == 0:
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
      M //= i
    else:
      break

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n;

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result;
       
sum = 1
for i in X.values():
  sum = (sum * cmb(i + N - 1, i) % 1000000007) % 1000000007
  
  
print(sum)

Submission status: Time Limit Exceeded

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

X = {}
for i in range(2, M):
  if M == 1:
    break
  while True:
    if M % i == 0:
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
      M //= i
    else:
      break

def P(n,r):
  return math.factorial(n) // math.factorial(n-r)
def C(n,r):
  return P(n,r) // math.factorial(r)
       
sum = 1
for i in X.values():
  sum = (sum * C(i + N - 1, i) % 1000000007) % 1000000007
  
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import bisect
import itertools

N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7

divisor = []
dict = {}

m = M
d = 2
while m != 1:
    while m % d == 0:
        # divisor.append(d)
        m //= d
        dict[d] = dict.get(d, 0) + 1
    d += 1
C = dict.values()
ret = 1


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

def combinations_count(n, r):
    a = max(r, n-r)
    b = min(r, n-r)
    r = 1
    for i in range(a+1, n+1):
        r *= i
    return r // math.factorial(b)


for c in C:
    ret *= combinations_count(c + N - 1, c)
    ret %= MOD

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import bisect
import itertools

N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7

divisor = []
dict = {}

m = M
d = 2
while m != 1:
    while m % d == 0:
        # divisor.append(d)
        m //= d
        dict[d] = dict.get(d, 0) + 1
    d += 1
C = dict.values()
ret = 1


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


for c in C:
    ret *= combinations_count(c + N - 1, c)
    ret %= MOD

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import bisect

N, M = [int(x) for x in input().split()]
MOD = 10**9 + 7

divisor = []
dict = {}

m = M
d = 2
while m != 1:
    while m % d == 0:
        divisor.append(d)
        m //= d
        dict[d] = dict.get(d,0) + 1
    d += 1
C = dict.values()
ret = 1

for c in C:
    ret = ret * math.factorial(c + N - 1)
    ret = ret // math.factorial(c)
    ret = ret // math.factorial(N - 1)
    ret = ret % MOD

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

s=0
I=m
R=m
t = {}

while s==0:
    for i in range(2,R+1):
        if I%i==0:
            I=I/i
            if I==1:
                s=1
            if i in t:
                t[i] = t[i] + 1
            else : 
                t[i] = 1
            break

sum = 1
for v in t.values():
    l = v + n - 1
    r = n - 1

    #print(str(l) + " C " + str(r))

    tmp = combinations_count(l,r)

    sum = sum * tmp
    sum = sum % 1000000007

    # print(str(sum) + " ",end="")
    # print()

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import *

def Prime_Factorization(M):
    factor_count_list = []
    root_M = int(sqrt(M))

    while root_M > 1:
        root_M = int(sqrt(M))

        for i in range(2, root_M + 1):
            e = 0
            while M % i == 0:
                e += 1
                M = M // i
            if e > 0:
                factor_count_list.append(e)
                break
        else:
            break

    if M > root_M:
        factor_count_list.append(1)

    return factor_count_list

def comb(num_object, num_bar):
    return factorial(num_object) // (factorial(num_object - num_bar) * factorial(num_bar))

def all_comb(N, factor_count_list):
    ans = 1
    for factor in factor_count_list:
        ans = (ans * comb(factor + N - 1, factor)) % (10 ** 9 + 7)
    return ans

def main():
    N, M = map(int, input().split())
    factor_count_list = Prime_Factorization(M)

    if (factor_count_list == 1):
        print(N)
    else:
        print(all_comb(N, factor_count_list))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

from collections import Counter

N, M = map(int, input().split())
D = 1000000000 + 7

def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
       primfac.append(n)
    return primfac


f = primes(M)
cntr = Counter(f)

ans = 1
for k,v in cntr.items():
    ans *= combinations_count(v+N-1,v) %D

print(ans%D)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

from collections import Counter

N, M = map(int, input().split())
D = 1000000000 + 7


def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
       primfac.append(n)
    return primfac


f = primes(M)
cntr = Counter(f)

ans = 1
for k,v in cntr.items():
    ans *= combinations_count(v+N-1,v)

print(ans%D)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

N, M = map(int,input().split())
def factors(n):    
  res = []
  cur = 2
  #for i in range(2, int(n**0.5)+2):
  while True:
    if n%cur == 0:
      res.append(cur)
      n /= cur
      cur = 2
      continue
    cur += 1
    if n == 1: break
  return res

fs = factors(M)
#fs.append(1)

def C(n,r):
  a=1
  b=1
  for i in range(r):
    a=a*(n-i)
    b=b*(r-i)
  return((a//b)%(10**9+7))

from collections import Counter
c = dict(Counter(fs))

ans = 1
for fact in c:
  freq = c[fact]
  ans *= C(N+freq-1,freq) 
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
import math


def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n;
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result;


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


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)

"""
n, m = [int(i) for i in input().split()]
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
count = 1
for i in range(len(divList)):
    count *= cmb(divList[i] + n - 1, min(divList[i], n-1))
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math


def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n;

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result;


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


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)

"""
n, m = [int(i) for i in input().split()]
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
count = 1
for i in range(len(divList)):
    count *= cmb(divList[i] + n - 1, divList[i])
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math


def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


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


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)

n, m = [int(i) for i in input().split()]
# n, m = 3, 12
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
# print(divList)

count = 1
for i in range(len(divList)):
    # print("{}:{}".format(divList[i]+n-1, n-1))
    # print(combinations_count(divList[i]+n-1, n-1))
    count *= cmb(divList[i] + n - 1, divList[i], mod)
    # count *= combinations_count(divList[i] + n - 1, divList[i])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math


def factorization(n):
    R = int(n)
    s = 0
    L = []
    while s == 0:
        for i in range(2, R + 1):
            if n % i == 0:
                n = n / i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L

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

n, m = [int(i) for i in input().split()]
# n, m = 3, 12
div = factorization(m)
divList = []
prevDiv = 0
for i in range(len(div)):
    if div[i] == prevDiv:
        divList[-1] += 1
    else:
        divList.append(1)
        prevDiv = div[i]
#print(divList)

count = 1
for i in range(len(divList)):
    #print("{}:{}".format(divList[i]+n-1, n-1))
    #print(combinations_count(divList[i]+n-1, n-1))
    count *= combinations_count(divList[i]+n-1, n-1)
print(count%(10**9 +7))