How to implement a function which calculates nCr mod m considering m = 10^5 1<= r <= n <= 10000
Main issue is data overflow. Can be done using Java Big Integers but that is time intensive.
Thanks !
See this property
nCr = n-1Cr + n-1Cr-1
So
nCr mod m = (n-1Cr mod m + n-1Cr-1 mod m) mod m
Now mix recursion with the above property and let me know if you need complete function in C or C++.
suppose
A(n,m) = 1 2 3 4 5 6 7 8 9 and B(p, q) = 1 1 1 1
What is best method to find min of square of difference of sub-matrices of A and B e.g.
sub-matrices of A =
1 2 | 2 3 | 4 5 | 5 6 3 4 | 5 6 | 7 8 | 8 9
Difference of first sub-matrix of A with B =
(1-1) (2-1) = | 0 1 (3-1) (4-1) | 2 3
sum of square of elements = 0*0 + 1*1 + 2*2 + 3*3 = 14
0*0 + 1*1 + 2*2 + 3*3 = 14
similar steps for other sub-matrices of A
Please suggest looking for an alternate method or algorithm which has time complexity less than O(n*m*p*q)
O(n*m*p*q)
Two numbers a and b are said to be co-prime if gcd(a,b) is 1.
Now my question is about the algorithm to find out if given two numbers are co-prime.
convert a number m to n with minimum operations. The operations allowed were -1 and *2.
For Eg : 4 and 6. Answer is 2. 1st operation : -1 -> 4-1 = 3. 2nd operation : * -> 3 * 2 =6.
Calculate all permutations for an array of integers.
For example: Given {3, 5, 8} - Output should be: { 3, 5, 8 }, { 3, 8, 5 }, { 5, 3, 8 }, { 5, 8, 3 }, { 8, 5, 3 }, { 8, 3, 5 }