Problem p02990 (python)

Fixed submission:
import math

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

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



for i in range(1,k+1):
    if n-k+1>=i:
        ans = (combinations_count(n-k+1,i)%(10**9+7)*combinations_count(k-1,i-1)%(10**9+7))
        print(ans%(10**9+7))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

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

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



for i in range(1,k+1):
    ans = (combinations_count(n-k+1,i)%(10**9+7)*combinations_count(k-1,i-1)%(10**9+7))
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
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

for i in range(1,k+1):
    ans = (cmb(n-k+1,i)*cmb(k-1,i-1))
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
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

for i in range(1,k+1):
    ans = (cmb(n-k+1,i)*cmb(k-1,i-1))
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))
n,k = map(int,input().split())


for i in range(1,k+1):
    ans = (combinations_count(n-k+1,i)*combinations_count(k-1,i-1))
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))
n,k = map(int,input().split())


for i in range(1,k+1):
    ans = (combinations_count(n-k+1,i)*combinations_count(k-1,i-1))
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,k+1):
    ans = (combinations_count(n-k+1,i)*combinations_count(k-1,i-1))%((10**9)+7)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,k+1):
    ans = (combinations_count(n-k+1,i)*combinations_count(k-1,i-1))%((10**9)+7)
    print(ans)