Problem p03253 (python)

Fixed submission:
N,M = map(int,raw_input().split())

def factorize(n):
	fct = []  # prime factor
	b, e = 2, 0  # base, exponent
	while b * b <= n:
		while n % b == 0:
			n = n / b
			e = e + 1
		if e > 0:
			fct.append((b, e))
		b, e = b + 1, 0
	if n > 1:
		fct.append((n, 1))
	return fct

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

fct= factorize(M)

ans = 1

for f in fct:
	ans=(ans *comb(f[1]+N-1,f[1]))%(10**9+7)

print ans

Buggy submission (verdict: Runtime Error):
def factorize(n):
    b,e = 2,0
    fct = []
    while b*b <= n:
        while n%b==0:
            n//=b
            e+=1
        if e>0:
            fct.append((b,e))
        b+=1
        e=0
    if n!=1:
        fct.append((n,1))
    return fct
    
N,M = list(map(int,input().split()))
 
pl = factorize(M)
 
max_coef=max([p[1] for p in pl])
 
 
if max_coef==0:
    print(N)
else:
 
    comb_list = [1]
    c = 1
    mod = 10**9+7
    for i in range(max_coef):
        c *= N+i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb_list.append(c)
 
    ans = 1
 
    for p in pl:
        ans*=comb_list[p[1]]
        ans %= mod
 
    print(ans)

Buggy submission (verdict: Runtime Error):
def factorize(n):
    b,e = 2,0
    fct = []
    while b*b <= n:
        while n%b==0:
            n//=b
            e+=1
        if e>0:
            fct.append((b,e))
        b+=1
    if n!=1:
        fct.append((n,1))
    return fct
    
N,M = list(map(int,input().split()))

pl = factorize(M)

max_coef=max([p[1] for p in pl])



if max_coef==0:
    print(N)
else:

    comb_list = [1]
    c = 1
    mod = 10**9+7
    for i in range(max_coef):
        c *= N+i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb_list.append(c)

    ans = 1

    for p in pl:
        ans*=comb_list[p[1]]
        ans %= mod

    print(ans)

Buggy submission (verdict: Runtime Error):
def factorize(n):
    b,e = 2,0
    fct = []
    while b*b < n:
        while n%b==0:
            n//=b
            e+=1
        if e>0:
            fct.append((b,e))
        b+=1
        e=0
    if n!=1:
        fct.append((n,1))
    return fct
    
N,M = list(map(int,input().split()))

pl = factorize(M)

max_coef=max([p[1] for p in pl])


if max_coef==0:
    print(N)
else:

    comb_list = [1]
    c = 1
    mod = 10**9+7
    for i in range(max_coef):
        c *= N+i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb_list.append(c)

    ans = 1

    for p in pl:
        ans*=comb_list[p[1]]
        ans %= mod

    print(ans)

Buggy submission (verdict: Runtime Error):
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)] 
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

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

pl = sieve_of_eratosthenes(int(M**0.5))


m = M
coef_list = [0]*len(pl)
for i,p in enumerate(pl):
    if m==1:
        break
    while m%p==0:
        m//=p
        coef_list[i]+=1

max_coef=max(coef_list)

if max_coef==0:
    print(N)
else:

    comb_list = [1]
    c = 1
    mod = 10**9+7
    for i in range(max_coef):
        c *= N+i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb_list.append(c)

    ans = 1

    for coef in coef_list:
        ans*=comb_list[coef]
        ans %= mod

    print(ans)