Problem p02990 (python)

Fixed submission:
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10**9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int((combinations(n, r-1) * (n-r+1)) // r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10**9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int((combinations(n, r-1) * (n-r+1)) / r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

# N = 5, K = 3
# i = 1 3 (青, 青, 青, 赤, 赤), (赤, 青, 青, 青, 赤), (赤, 赤, 青, 青, 青)
# (0, 2), (1, 1), (2, 0) 3c2 = 3 * 2 / 2 * 1
# i = 1, B = 3, R = 2
# i = 2 6 (青, 青, 赤, 青, 赤), (青, 青, 赤, 赤, 青), (赤, 青, 青, 赤, 青), (赤, 青, 赤, 青, 青), (青, 赤, 青, 青, 赤), (青, 赤, 赤, 青, 青)
# (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 1, 0), () 4c2 = 4 * 3 / 2 * 1 = 6
# i = 2, B = 3, R = 2
# i = 3 1 (青, 赤, 青, 赤, 青)
# (1, 1) 2c1 = 1
# i = 3, B = 3, R = 2

# i = 1, N = 5, B = 3, R = 2, ans = 3
# i = 2, N = 5, B = 3, R = 2, ans = 6
# i = 3, N = 5, B = 3, R = 2, ans = 1

# N = 6, K = 3
# i = 1 4: (BBBRRR), (RBBBRR), (RRBBBR), (RRRBBB)
# (0, 3), (1, 2), (2, 1), (3, 0)
# i = 1, B = 3, R = 3
# i = 2 : (BBRBRR), (BRBBRR), (BRRBBR) * 2

# B = 3, i = 1: B / i = 1
# B = 3, i = 2: B / i = 3
# B = 3, i = 3: B / i = 1

# B = 1: 1 * x = 3
# B = 2: 2 * x = 6
# B = 3: 1 * x = 1


@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r )

def f(i):
    return (combinations(N - K + 1, i)  % (10 ** 9 + 7)) * (combinations(K - 1, i - 1)  % (10 ** 9 + 7))

for i in range(1, K + 1):
    print(f(i) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

# N = 5, K = 3
# i = 1 3 (青, 青, 青, 赤, 赤), (赤, 青, 青, 青, 赤), (赤, 赤, 青, 青, 青)
# (0, 2), (1, 1), (2, 0) 3c2 = 3 * 2 / 2 * 1
# i = 1, B = 3, R = 2
# i = 2 6 (青, 青, 赤, 青, 赤), (青, 青, 赤, 赤, 青), (赤, 青, 青, 赤, 青), (赤, 青, 赤, 青, 青), (青, 赤, 青, 青, 赤), (青, 赤, 赤, 青, 青)
# (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 1, 0), () 4c2 = 4 * 3 / 2 * 1 = 6
# i = 2, B = 3, R = 2
# i = 3 1 (青, 赤, 青, 赤, 青)
# (1, 1) 2c1 = 1
# i = 3, B = 3, R = 2

# i = 1, N = 5, B = 3, R = 2, ans = 3
# i = 2, N = 5, B = 3, R = 2, ans = 6
# i = 3, N = 5, B = 3, R = 2, ans = 1

# N = 6, K = 3
# i = 1 4: (BBBRRR), (RBBBRR), (RRBBBR), (RRRBBB)
# (0, 3), (1, 2), (2, 1), (3, 0)
# i = 1, B = 3, R = 3
# i = 2 : (BBRBRR), (BRBBRR), (BRRBBR) * 2

# B = 3, i = 1: B / i = 1
# B = 3, i = 2: B / i = 3
# B = 3, i = 3: B / i = 1

# B = 1: 1 * x = 3
# B = 2: 2 * x = 6
# B = 3: 1 * x = 1


@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r )

def f(i):
    return combinations(N - K + 1, i) * combinations(K - 1, i - 1)

for i in range(1, K + 1):
    print(f(i) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10000)

N, K = map(int, input().split())

# N = 5, K = 3
# i = 1 3 (青, 青, 青, 赤, 赤), (赤, 青, 青, 青, 赤), (赤, 赤, 青, 青, 青)
# (0, 2), (1, 1), (2, 0) 3c2 = 3 * 2 / 2 * 1
# i = 1, B = 3, R = 2
# i = 2 6 (青, 青, 赤, 青, 赤), (青, 青, 赤, 赤, 青), (赤, 青, 青, 赤, 青), (赤, 青, 赤, 青, 青), (青, 赤, 青, 青, 赤), (青, 赤, 赤, 青, 青)
# (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 1, 0), () 4c2 = 4 * 3 / 2 * 1 = 6
# i = 2, B = 3, R = 2
# i = 3 1 (青, 赤, 青, 赤, 青)
# (1, 1) 2c1 = 1
# i = 3, B = 3, R = 2

# i = 1, N = 5, B = 3, R = 2, ans = 3
# i = 2, N = 5, B = 3, R = 2, ans = 6
# i = 3, N = 5, B = 3, R = 2, ans = 1

# N = 6, K = 3
# i = 1 4: (BBBRRR), (RBBBRR), (RRBBBR), (RRRBBB)
# (0, 3), (1, 2), (2, 1), (3, 0)
# i = 1, B = 3, R = 3
# i = 2 : (BBRBRR), (BRBBRR), (BRRBBR) * 2

# B = 3, i = 1: B / i = 1
# B = 3, i = 2: B / i = 3
# B = 3, i = 3: B / i = 1

# B = 1: 1 * x = 3
# B = 2: 2 * x = 6
# B = 3: 1 * x = 1


@lru_cache(maxsize=10*9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int(combinations(n, r-1) * (n-r+1) / r )

def f(i):
    return combinations(N - K + 1, i) * combinations(K - 1, i - 1)

for i in range(1, K + 1):
    print(f(i) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

# N = 5, K = 3
# i = 1 3 (青, 青, 青, 赤, 赤), (赤, 青, 青, 青, 赤), (赤, 赤, 青, 青, 青)
# (0, 2), (1, 1), (2, 0) 3c2 = 3 * 2 / 2 * 1
# i = 1, B = 3, R = 2
# i = 2 6 (青, 青, 赤, 青, 赤), (青, 青, 赤, 赤, 青), (赤, 青, 青, 赤, 青), (赤, 青, 赤, 青, 青), (青, 赤, 青, 青, 赤), (青, 赤, 赤, 青, 青)
# (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 1, 0), () 4c2 = 4 * 3 / 2 * 1 = 6
# i = 2, B = 3, R = 2
# i = 3 1 (青, 赤, 青, 赤, 青)
# (1, 1) 2c1 = 1
# i = 3, B = 3, R = 2

# i = 1, N = 5, B = 3, R = 2, ans = 3
# i = 2, N = 5, B = 3, R = 2, ans = 6
# i = 3, N = 5, B = 3, R = 2, ans = 1

# N = 6, K = 3
# i = 1 4: (BBBRRR), (RBBBRR), (RRBBBR), (RRRBBB)
# (0, 3), (1, 2), (2, 1), (3, 0)
# i = 1, B = 3, R = 3
# i = 2 : (BBRBRR), (BRBBRR), (BRRBBR) * 2

# B = 3, i = 1: B / i = 1
# B = 3, i = 2: B / i = 3
# B = 3, i = 3: B / i = 1

# B = 1: 1 * x = 3
# B = 2: 2 * x = 6
# B = 3: 1 * x = 1

def combinations(n, c):
    if n < c:
        return 1
    x = 1
    for i in range(n-c+1, n+1):
        x = x * i
    for i in range(1, c+1):
        x /= i
    return int(x)

def f(i):
    B = K
    R = N - K

    return combinations(R + 1, i) * combinations(K - 1, i - 1)

for i in range(1, K + 1):
    print(f(i) % (10 ** 9 + 7))