HACKER RANK Project Euler 15 - Lattice Paths - Solution.'Py'


 Project Euler Challenges-15 - Lattice Paths Solution



 


Problem Statement
This problem is a programming version of Problem 15 from projecteuler.net
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a N×M grid? As number of ways can be very large, print it modulo 109+7.
Input Format
The first line contains an integer T , i.e., number of test cases.
Next T lines will contain integers N and M.
Output Format
Print the values corresponding to each test case.
Constraints
1 ≤ T ≤ 103
1 ≤ N ≤ 500
1 ≤ M ≤ 500
Sample Input
2
2 2
3 2
Sample Output
6
10

Solution:

   #from Euler import binomial
from math import *
t = input()
while(t>0):
    t-=1
    n, m = map(int,raw_input().split())
    print (factorial(n+m) / factorial(n) / factorial(m))%((10**9)+7)

Thanks for Visiting, Hope this helps you....


 

Comments

Popular Posts