Problem:


問題 5 

　IOI 宝飾店ではビーズのネックレスを売り出すことになった．
ビーズは n 色あり，
これらをそれぞれ m 個以上ずつ選んで r 個のビーズからなるネックレスとし，
１つずつ化粧箱に入れて販売したい．
色の組合せが違うものをすべて１つずつ用意したいが，
化粧箱を何個用意したらよいか店員の誰もわからない．
n, m, r によっては現実的でない個数の化粧箱が必要となるのではないかと店長は心配している．
IOI 宝飾店の店長に代わって，
必要な化粧箱の個数を出力するプログラムを作成しなさい．
n, m, r は整数で，0≦m＜n≦r≦10000 である．

　入力ファイルは１行で，
空白を区切りとして n, m, r がこの順に書いてある．
入力ファイル５つのうちの３つでは n≦10 である．

　出力ファイルにおいては，
出力の最後の行にも改行コードを入れること．

入出力例

入力例１

2 0 3

出力例１

4

入力例２

3 1 4

出力例２

3

入力例３

4 2 5

出力例３

0

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
2 0 3


Sample output:
4

Submission status: Wrong Answer

Solution code:
n,m,r=map(int,input().split());
a=n+r-n*m-1;b=r-n*m;
s=1;
if a<b or a<0 or b<0:s=0;
else:
    if b>a-b:b=a-b;
    for i in range(b):s=s*(a-i)/(i+1);
print(s)

Submission status: Wrong Answer

Solution code:
n,m,r=map(int,input().split())
r-=n*m
if r<0:print(0);exit(0);
from math import *
print(factorial(n+r-1//factorial(r))//factorial(n-1))

Submission status: Wrong Answer

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 d=1//d
 for i in range(n-1,r+n-1):d*=i+1
 print(d)

Submission status: Wrong Answer

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 d=1/d
 for i in range(n-1,r+n-1):d*=i+1
 print(int(d))

Submission status: Wrong Answer

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 a=1
 for i in range(r):a*=(i+n)/-~i
 print(int(a))

Submission status: Wrong Answer

Solution code:
def foo(infile, outfile):
    import math
    n, m, r=infile.readline().split()
    n=int(n)
    m=int(m)
    r=int(r)
    print 0
    if r-n*m >= 0:
        print math.factorial(r-n*m+n-1)/math.factorial(r-n*m)/math.factorial(n-1)
    else :
        print 0

if __name__ == "__main__":
    import sys
    foo(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split());
a=n+r-n*m-1;b=r-n*m;
s=1;
if a<b or a<0 or b<0:s=0;
else:
    if b>a-b:b=a-b;
    for i in range(b):s=s*(a-i)//(i+1);
print(s)

Submission status: Accepted

Solution code:
def fact(a):
    res = 1
    while a:
        res *= a
        a -= 1
    return res

n,m,r = map(int,input().split())
r-=n*m
if r < 0:
    print(0)
else:
    print(fact(r+n-1)//fact(n-1)//fact(r))

Submission status: Accepted

Solution code:
def fact(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

def combination(n, k):
    return fact(n)//fact(n-k)//fact(k)

n, m, r = list(map(int, input().split()))

print(combination(r - n*m + n - 1, n-1))

Submission status: Accepted

Solution code:
def fact(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res
 
def combination(n, k):
    return fact(n)//fact(n-k)//fact(k)
 
n, m, r = list(map(int, input().split()))
 
print(combination(r - n*m + n - 1, n-1))

Submission status: Accepted

Solution code:
import math
def combination(p, q):
    if q < 0 or p < q:
        return 0
    return math.factorial(p) // math.factorial(q) // math.factorial(p - q)
a, b, c = map(int, input().split())
c -= a * b
print(combination(c + a - 1, c))

Submission status: Accepted

Solution code:
from math import factorial                                    
                                                              
# get input                                                   
n, m, r = (int(x) for x in input().strip().split())           
                                                              
# rest of beads                                       
rest = r - n * m                                              
                                                              
# rest + partition                                            
x = rest + (n - 1)                                            
                                                              
# combination (partition + rest)! / (rest! * partition!)      
try:                                                          
  print(factorial(x) // factorial(rest) // factorial(n - 1))  
except ValueError:                                            
  print(0)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=n*m
if r<0:print(0);exit(0);
from math import *
print(factorial(n+r-1)//factorial(r)//factorial(n-1))

Submission status: Accepted

Solution code:
from math import *
n,m,r=map(int,input().split())
r-=m*n
print(0 if r<0 else factorial(n-1+r)//factorial(n-1)//factorial(r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0591

"""
import sys
from sys import stdin
from math import factorial
input = stdin.readline


def solve(n, m, r):
    # https://www.ioi-jp.org/joi/2005/2006-m2-prob_and_sol/2006-m2-t5-review.html
    if n * m > r:
        return 0
    ans = factorial(n+r-m*n-1) // factorial(n-1) // factorial(r - m*n)
    return ans


def main(args):
    n, m, r = map(int, input().split())
    result = solve(n, m, r)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
a,b=sorted([n-1,r-m*n])
d=1
for i in range(a):d*=i+1
u=1
for i in range(b,a+b):u*=i+1
print(0 if a<1 else u//d)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
a,b=sorted([n-1,r-m*n])
if a<1:print(0)
else:
 d=1
 for i in range(a):d*=i+1
 u=1
 for i in range(b,a+b):u*=i+1
 print(u//d)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=n*m
if r<0:print(0)
else:
 from math import*
 print(factorial(n+r-1)//factorial(r)//factorial(n-1))

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=n*m
if r<0:print(0)
else:
 from math import factorial as f
 print(f(n+r-1)//f(r)//f(n-1))

Submission status: Accepted

Solution code:
def s():
 n,m,r=map(int,input().split())
 r-=n*m
 if r<0:print(0)
 else:
  from math import factorial as f
  print(f(n+r-1)//f(r)//f(n-1))
if'__main__'==__name__:s()

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 u=1
 for i in range(n-1,r+n-1):u*=i+1
 print(u//d)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 u=1
 for i in range(n,r+n):u*=i
 print(u//d)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 a=1
 for i in range(r):a*=i+n
 for i in range(r):a//=i+1
 print(a)

Submission status: Accepted

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 u=1
 for i in range(r):u*=i+n
 print(u//d)

Submission status: Accepted

Solution code:
import math
n, m, r = map(int, input().split())
a = r - n * m
def combination(p, q):
    if q < 0 or p < q:
        return 0
    return math.factorial(p) // math.factorial(q) // math.factorial(p - q)
if a < 0:
    print(0)
else:
    print(int(combination(a + n - 1, a)))

Submission status: Accepted

Solution code:
# AOJ 0591: Beads
# Python3 2018.6.29 bal4u
# (n + r - mn - 1) ! / {(n - 1) ! × (r - mn) !}

import math
n, m, r = map(int, input().split())
if r-m*n < 0: print(0)
else: print(math.factorial(n+r-m*n-1)//(math.factorial(n-1)*math.factorial(r-m*n)))

Submission status: Accepted

Solution code:
def nCr(n, r):
  ret = 1
  for i in range(r):
    ret *= n - i
  for i in range(r):
    ret /= i + 1
  return ret

(n, m, r) = map(int, raw_input().split())

N = r - m * n

if N < 0:
  print 0
else:
  print nCr(N + n - 1, n - 1)

Submission status: Accepted

Solution code:
def fact(x):
    res = 1
    for i in xrange(1, x + 1):
        res *= i
    return res

def comb(a, b):
    if(a < b or b < 0):return 0
    if(b == 0):return 1
    return fact(a)/fact(b)/fact(a-b)

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Submission status: Accepted

Solution code:
def foo(infile, outfile):
    import math
    n, m, r=infile.readline().split()
    n=int(n)
    m=int(m)
    r=int(r)
    if r-n*m >= 0:
        print math.factorial(r-n*m+n-1)/math.factorial(r-n*m)/math.factorial(n-1)
    else :
        print 0

if __name__ == "__main__":
    import sys
    foo(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:
def kaijou(n):
	res=1
	for i in xrange(1,n+1):
		res*=i
	return res

def comb(a,b):
	if(a<b or b<0):return 0
	if(b==0):return 1
	return kaijou(a)/kaijou(b)/kaijou(a-b)

a,b,c=map(int,raw_input().split())
c-=a*b
print comb(c+a-1,c)

Submission status: Accepted

Solution code:
import math
import random
import sys



def main():

    n,m,r = map(int,input().split())
    if n*m>r:
        print(0)
        return
    
    r -= n*m
    
    ans=1
    
    for i in range(r+n-1):
        ans*=i+1
    for i in range(r+1):
        if i>0:
            ans//=i
    for i in range(n-1+1):
        if i>0:
            ans//=i
            
            
    print(int(ans))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n, m, r = list(map(int, input().split(" ")))

if n * m > r:
    print(0)
    sys.exit()

r = r - n * m
res = 1
for i in range(1, n + r):
    res *= i
for i in range(1, n):
    res //= i
for i in range(1, r + 1):
    res //= i
print(int(res))

Submission status: Accepted

Solution code:
import math
n, m, r = map(int, input().split())
if r-m*n < 0: 
    print(0)
else: 
    print(math.factorial(n+r-m*n-1)//(math.factorial(n-1)*math.factorial(r-m*n)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

def fact(n):
    if n <= 1:
        return 1
    return n * fact(n - 1)

n, m, r = map(int, raw_input().split())

if r - n * m < 0:
    print 0
else:
    print fact(r - n * m + n - 1) / fact(r - n * m) / fact(n - 1)

Submission status: Accepted

Solution code:
import math
dat = input()
dat = dat.split()
n = int(dat[0])
m = int(dat[1])
r = int(dat[2])
if r-m*n < 0:
    sum = 0
else:
    sum = math.factorial(r-m*n+n-1)//math.factorial(r-m*n)//math.factorial(n-1)
print(sum)

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split());
a=n+r-n*m-1,b=r-n*m;
s=1;
if a<b||a<0||b<0:s=0;
else:
    if b>a-b:b=a-b;
	for i in range(b):s=s*(a-i)/(i+1);
print(s)

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split());
a=n+r-n*m-1;b=r-n*m;
s=1;
if a<b||a<0||b<0:s=0;
else:
    if b>a-b:b=a-b;
	for i in range(b):s=s*(a-i)/(i+1);
print(s)

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split());
a=n+r-n*m-1;b=r-n*m;
s=1;
if a<b or a<0 or b<0:s=0;
else:
    if b>a-b:b=a-b;
	for i in range(b):s=s*(a-i)/(i+1);
print(s)

Submission status: Runtime Error

Solution code:
def fact(a): return a and a*fact(a-1) or 1

n,m,r = map(int,input().split())
r-=n*m
if r < 0:
    print(0)
else:
    print(fact(r+n-1)//fact(n-1)//fact(r))

Submission status: Runtime Error

Solution code:
import math
def combination(p, q):
    if q < 0 or p < q:
        return 0
    return math.factorial(p) / math.factorial(q) / math.factorial(p - q)
a, b, c = map(int, input().split())
c -= a * b
print(int(combination(c + a - 1, c)))

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
r-=n*m
if r<0:print(0);exit(0);
from math import *
print(int(factorial(n+r-1)/factorial(r)/factorial(n-1)))

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
a,b=sorted([n-1,r-m*n])
A=1
for i in range(a):A*=i+1
B=A
for i in range(a,b):B*=i+1
C=B
for i in range(b,a+b):C*=i+1
print(int(C/B/A))

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
a,b=sorted([n-1,r-m*n])
A=1
for i in range(a):A*=i+1
B=A
for i in range(a,b):B*=i+1
C=B
for i in range(b,a+b):C*=i+1
print([int(C/B/A),0][a<1])

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
a,b=sorted([n-1,r-m*n])
A=1
for i in range(a):A*=i+1
B=A
for i in range(a,b):B*=i+1
C=B
for i in range(b,a+b):C*=i+1
print(0 if a<1 else int(C/B/A))

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 a=1
 for i in range(r):a*=i+n/~-i
 print(int(a))

Submission status: Runtime Error

Solution code:
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 a=1
 for i in range(r):a*=(i+n)/-~i
 print(int(a+.1))

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    print(int(comb(a + n - 1, n - 1)))

Submission status: Runtime Error

Solution code:
import math
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    print(int(math.factorial(a + n - 1) / math.factorial(n - 1) / math.factorial(a)))

Submission status: Runtime Error

Solution code:
import math
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    b = 1
    if n - 1 > a:
        for i in range(a):
            b *= a + n - 1 - i
        for i in range(1, a + 1):
            b /= i
    else:
        for i in range(n - 1):
            b *= a + n - 1 - i
        for i in range(1, n):
            b /= i
    print(int(b))

Submission status: Runtime Error

Solution code:
import math
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    b = 1
    if n - 1 > a:
        for i in range(a):
            b *= a + n - 1 - i
        for i in range(1, a + 1):
            b = int(b / i)
    else:
        for i in range(n - 1):
            b *= a + n - 1 - i
        for i in range(1, n):
            b /= int(b / i)
    print(int(b))

Submission status: Runtime Error

Solution code:
import math
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    b = 1
    if n - 1 > a:
        for i in range(a):
            b *= a + n - 1 - i
        for i in range(1, a + 1):
            b = int(b / i)
    else:
        for i in range(n - 1):
            b *= a + n - 1 - i
        for i in range(1, n):
            b = int(b / i)
    print(int(b))

Submission status: Runtime Error

Solution code:
def comb(a, b):
    if(a < b or b < 0):return 0
    if(b > a - b)return comb(a, a - b)
    return comb(a, b - 1) * (a - b + 1) / b

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Submission status: Runtime Error

Solution code:
def comb(a, b):
    if(a < b or b < 0):return 0
    if(b > a - b):return comb(a, a - b)
    return comb(a, b - 1) * (a - b + 1) / b

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Submission status: Runtime Error

Solution code:
def comb(a, b):
    if(a < b or b < 0):return 0
	if(b == 0):return 1
    if(b > a - b):return comb(a, a - b)
    return comb(a, b - 1) * (a - b + 1) / b

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Submission status: Runtime Error

Solution code:
def comb(a, b):
    if(a < b or b < 0):return 0
    if(b == 0):return 1
    if(b > a - b):return comb(a, a - b)
    return comb(a, b - 1) * (a - b + 1) / b

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Submission status: Runtime Error

Solution code:
def kaijou(n):
	res=1
	for i in xrange(1,x+1):
		res*=i
	return res

def comb(a,b):
	if(a<b or b<0):return 0
	if(b==0):return 1
	return kaijou(a)/kaijou(b)/kaijou(a-b)

a,b,c=map(int,raw_input().split())
c-=a*b
print comb(c+a-1,c)