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)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Count Fox Sequences
You are viewing a single comment's thread. Return to all comments →
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