Problem p02990 (python)

Fixed submission:
import math


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


n, k = map(int, input().split())
mod = 10**9+7
for i in range(1, k+1):
    if n-k+1 >= i:
        print(comb(n-k+1, i)*comb(k-1, i-1) % mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math


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


n, k = map(int, input().split())
mod = 10**9+7
for i in range(1, k+1):
    print(comb(n-k+1, i)*comb(k-1, i-1) % mod)

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
for i in range(k):
    if n-k+1 < i:
        print(0)
    else:
        print(((cmb(n-k+1, i+1) % (10 ** 9 + 7)) * (cmb(k-1, i) % (10 ** 9 + 7))) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
for i in range(k):
     if n-k+1 < i:
        print(0)
    else:
        print(((cmb(n-k+1, i+1) % (10 ** 9 + 7)) * (cmb(k-1, i) % (10 ** 9 + 7))) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
d = [0]*k
for i in range(k):
    a = cmb(k-1, i)
    div = math.ceil(a)
    d[i] = (cmb(n-k+1, i+1) % (10 ** 9 + 7)) * (div % (10 ** 9 + 7)) % % (10 ** 9 + 7)


    #     s = math.factorial(n-k+1)//math.factorial(i+1)
for i in d:
    print(i)

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
d = [0]*k
d[0] = n-k+1
for i in range(1, k):
    a = cmb(k-1, i)/i
    div = math.ceil(a)
    d[i] = cmb(n-k+1, i+1)*div


    #     s = math.factorial(n-k+1)//math.factorial(i+1)
for i in d:
    print(i % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
d = [0]*k
d[0] = n-k+1
for i in range(1, k):
    a = cmb(k-1, i)/i
    div = math.ceil(a)
    if k % (i+1) == 0:
        d[i] = cmb(n-k+1, i+1)*(div-1) + 1
    else:
        d[i] = cmb(n-k+1, i+1)*div


    #     s = math.factorial(n-k+1)//math.factorial(i+1)
for i in d:
    print(i % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
d = [0]*k
d[0] = n-k+1
for i in range(1, k):
    a = cmb(k-1, i)/i
    div = math.ceil(a)
    if k % (i+1) == 0:
        d[i] = cmb(n-k+1, i+1)
    elif (i+1) % k == 0:
        d[i] = cmb(n-k+1, i+1)*(div-1) + 1
    else:
        d[i] = cmb(n-k+1, i+1)*div


    #     s = math.factorial(n-k+1)//math.factorial(i+1)
for i in d:
    print(i % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math
import itertools
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

n, k = map(int, input().split())
d = [0]*k
d[0] = n-k+1
for i in range(1, k):
    a = cmb(k-1, i)/i
    div = math.ceil(a)
    if k % (i+1) == 0:
        d[i] = cmb(n-k+1, i+1)
    else:
        d[i] = cmb(n-k+1, i+1)*div


    #     s = math.factorial(n-k+1)//math.factorial(i+1)
for i in d:
    print(i % (10 ** 9 + 7))