We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Important: The following prcedure gives correct result for the testcase 0, testcase 1, and testcase 9.
Procedure:
Let m=hi-lo+1.
My procedure is as follows:
First Step:
Calculate the number of possible solutions of the problem
x1+x2+...+xk=n such that 1<= x1,x2,...,xk <= t
where t varies from ceil(n/k) to n-k+1.
Second Step:
Multiply this number with C(n,k).
Third step:
varies k from (1, min(n-1,m))
The code
# Enter your code here. Read input from STDIN. Print output to STDOUT
import math
modnu=10**9+7
def nchoosek(n,k):
# calculating n choose k
global modnu
if n < k:
return 0
elif k==0:
return 1
else:
t=1
u=max(k,n-k)
for i in range(1,min(k,n-k)+1):
t=(t*(u+i)/i)%modnu
return t
def foxsequence(n,m):
global modnu
fox_se=m
for k in range(2,min(n-1,m)+1):
t=0
for l in range(int(math.ceil(n/float(k))),n-k+2):
for r in range(k):
if n-l*(r+1)+r-1>= k-2:
t=t+((-1)**(r%2))*nchoosek(k-1,r)*nchoosek(n-l*(r+1)+r-1,k-2)
else:
break
fox_se=(fox_se+(t*k*nchoosek(m,k)))%modnu
return fox_se
n=input()
for i in range(n):
t=map(int, raw_input().split())
print foxsequence(t[0],t[2]-t[1]+1)
Solution in Python 3
Important: The following prcedure gives correct result for the testcase 0, testcase 1, and testcase 9.
Procedure: Let m=hi-lo+1.
My procedure is as follows:
First Step: Calculate the number of possible solutions of the problem
x1+x2+...+xk=n such that 1<= x1,x2,...,xk <= t
where t varies from ceil(n/k) to n-k+1.
Second Step: Multiply this number with C(n,k).
Third step:
varies k from (1, min(n-1,m))
The code
The answer it seems should be there are 5 possible fox sequences not 4. What am I missing here? 4 4 4 4 *4 4 4 5* 4 4 5 5 *4 5 5 5* 5 5 5 5