
Buying no item is also a valid way
Input : N = 3, K = 2
Output : 4
Explanation:
There are 3 type of items; he can buy 2 items in 3 ways ({1,2}, {2,3} and {1,3}). and 0 items in 1 way, hence there will be a total of 4 ways.
The first line contains a single integer 'T' denoting the number of test cases to be run. Then the test cases follow.
The only line in the input contains two integers separated by a space, 'N' and 'K' denoting the number of items and the worth of one coin, respectively.
For each test case, print an integer denoting the number of ways to buy some of the items for each test case, as specified above.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 10^12
1 <= K <= 10^3
Time Limit: 1 sec.
In general, we have to compute the sum ∑ NC(M*K) modulo 100000 where M is from 0 to (N/K).
Here, the binomial coefficients can be taken from the polynomial coefficients as (1+x)^n.
We want to find the sum of the coefficients of x^i, where i is a multiple of K. We can take the powers modulo K here.
So, we can compute the coefficients of (1+x)^n using repeated squaring but only keep the first K coefficients. This will require O(log(n)) polynomial coefficients with, at most degree, K. We will use the efficient polynomial multiplication method FFT.