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.
Can anyone improve my code, Test cases 5,6,7,8 are timed out:
from math import factorial
for _ in range(0, int(raw_input())):
m, n = map(int, raw_input().split())
p1 = 1
if (m > n):
for i in range(m, m+n-1):
p1 = p1 * i
print (p1/factorial(n-1))%((10**9)+7)
else:
for i in range(n, m+n-1):
p1 = p1 * i
print (p1/factorial(m-1))%((10**9)+7)
Matrix Tracing
You are viewing a single comment's thread. Return to all comments →
Can anyone improve my code, Test cases 5,6,7,8 are timed out:
from math import factorial for _ in range(0, int(raw_input())): m, n = map(int, raw_input().split()) p1 = 1 if (m > n): for i in range(m, m+n-1): p1 = p1 * i print (p1/factorial(n-1))%((10**9)+7) else: for i in range(n, m+n-1): p1 = p1 * i print (p1/factorial(m-1))%((10**9)+7)