You are given a pyramid of the following form with an infinite number of rows:112 32 34 5 64 5 67 8 9 107 8 9 10………………….
From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (For example, you can make the following moves: 1→2,1→3,6→9,6→101→2,1→3,6→9,6→10, while you cannot make moves 2→62→6 or 2→72→7).
You are given a starting cell ss and an ending cell ee. Starting at cell ss, find the number of ways to reach cell ee. This number can be large, so print the answer modulo 109+7109+7.
Two ways are said to be different if there exists at least one cell which was visited in one of the ways but not the other one.
- The first line of input contains a single integer TT, the number of test cases. The description of TT test cases follows.
- The first and only line of each test case contains two space-separated integers ss and ee, denoting the starting and the ending cell respectively.
For each test case, output a single line containing one integer: the number of ways to go from ss to ee modulo 109+7109+7.
Subtask 1(100 points): Original constraints
Sample Input 1
3 2 7 1 5 5 3
Sample Output 1
1 2 0
In the first test case, there exists only 11 way to move from 22 to 77, which is:
In the second test case, there exist 22 ways to move from 11 to 55, which are:
In the third test case, it is not possible to move from 55 to 33.
Will be updated today.
Refer and Earn Rs. 1200 per referral on Upstox
Click here to know more
Read More Post Here