Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce

def nCr(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())
MOD = 10 ** 9 + 7

for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    else:
        ans = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
    if (N - K) < (i - 1):
        red = 0
#        print('red0: ' + str(red))
    elif i == 1:
        red = (N - K) + 1
        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nHk(i + 1, N - K - i - 1)
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

#def nCr(n,r):
#    f = math.factorial
#    return int(f(n) / f(r) / f(n-r))

def nCr(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())
MOD = 10 ** 9 + 7

for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    else:
        ans = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    else:
        ans = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    ans = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
    if (N - K) < (i - 1):
        red = 0
#        print('red0: ' + str(red))
    elif i == 1:
        red = (N - K) + 1
#        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nCr(N-K+1, i)
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)
#    print('ans: ' + str(ans))

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    a = nCr(K - 1, i - 1) % MOD
    b = nHk(i + 1, N - K - (i - 1)) % MOD
    ans = a * b % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
    ans = nCr(K - 1, i - 1) * nHk(i + 1, N - K - (i - 1)) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
#    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
    if (N - K) <= (i - 1):
        red = 0
#        print('red0: ' + str(red))
    elif i == 1:
        red = (N - K) + 1
#        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nHk(i + 1, N - K - (i - 1))
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)
#    print('ans: ' + str(ans))

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
#    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
#    if (N - K) < (i - 1):
#        red = 0
#        print('red0: ' + str(red))
    if i == 1:
        red = (N - K) + 1
#        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nHk(i + 1, N - K - (i - 1))
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)
#    print('ans: ' + str(ans))

Buggy submission (verdict: Runtime Error):
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

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

for i in range(1, K + 1):
#    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
    if (N - K) < (i - 1):
        red = 0
#        print('red0: ' + str(red))
    elif i == 1:
        red = (N - K) + 1
#        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nHk(i + 1, N - K - (i - 1))
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)
#    print('ans: ' + str(ans))