Problem p03253 (python)

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

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



N = n + 100
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 )

#print(combo(2,1))

#print(m)
fac = {}
mm = m
#print(mm)
count = 0
while mm % 2 == 0:
    count += 1
    mm //= 2
if count > 0:
    fac[2] = count
f = 3
count = 0
while f ** 2 <= mm:
    while mm % f == 0:
        count += 1
        mm //= f
        #print(f,count)
    if count > 0:
        fac[f] = count
        count = 0
    f += 2
    #print(fac)
if mm != 1:
    if mm in fac:
        fac[mm] += 1
    else:
        fac[mm] = 1
#print(fac)

count = 1

for i in fac:
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i],mod)) % mod
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
mod = 10 ** 9 + 7

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


mod = 10**9+7 #出力の制限
N = n + 100
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 )

#print(combo(2,1))


fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * cmb(fac[i]+n-1,fac[i],mod)) % mod
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        return ret

#print(combo(2,1))


fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        return ret

#print(combo(2,1))


fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
memo = [{} for _ in range(n+30)]
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    elif q in memo[p]:
        return memo[p][q]
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        memo[p][q] = ret
        return ret

#print(combo(2,1))


fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
memo = [{} for _ in range(n+30)]
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    elif q in memo[p]:
        return memo[p][q]
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        memo[p][q] = ret
        return ret

#print(combo(2,1))


fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
memo = [{} for _ in range(30)]
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    elif q in memo[p]:
        return memo[p][q]
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        memo[p][q] = ret
        return ret

#print(combo(2,1))

n,m = map(int,input().split())
fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
memo = [{} for _ in range(30)]
MOD = 10 ** 9 + 7

def combo(p,q):
    if p == 0:
        return 1
    elif q == 0 or q == p:
        return 1
    elif q in memo[p]:
        return memo[p][q]
    else:
        ret = (combo(p-1,q-1) + combo(p-1,q)) % MOD
        memo[p][q] = ret
        return ret

#print(combo(2,1))

n,m = map(int,input().split())
fac = [0] * (m+1)
mm = m
for i in range(2,m+1):
    while mm % i == 0:
        mm = mm // i
        fac[i] += 1
        #print(mm,fac)

count = 1

for i in range(2,m+1):
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i])) % MOD
    #print(count)
    
print(count)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 +7

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

div = []

for i in range(1,int(m ** (1/2)) + 1):
    if m % i == 0:
        div.append(i)
        div.append(m//i)

memo = [{} for _ in range(m+1)]
def count(k,n):
    if n == 1:
        return 1
    if n in memo[k]:
        return memo[k][n]
    ret = 0
    for x in div:
        if k % x == 0:
            ret = (ret + count(k//x,n-1)) % MOD
    memo[k][n] = ret
    return ret

print(count(m,n))

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 +7

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

div = []

for i in range(1,int(m ** (1/2)) + 1):
    if m % i == 0:
        div.append(i)
        div.append(m//i)

memo = [{} for _ in range(m+1)]
def count(k,n):
    if n == 1:
        return 1
    if n in memo[k]:
        return memo[k][n]
    ret = 0
    for x in div:
        if k % x == 0:
            ret = (ret + count(k//x,n-1)) % MOD
    memo[k][n] = ret
    return ret

print(count(m,n))