Problem Description
You are given an integer array A. There is a function,F for two integers X and Y with another variable B(base).
Now for caluculating the functional value first convert X and Y in Base B and then ith bit of F(X,Y,B) = (Xi+Yi)%B.
You have to return the maximum functional value possible for any pair of elements of Array A in base B. Please note that you can't take two elements for pair from the same index.
NOTE: Array elements are in base 10 and you have to return your answer also in base 10(calculated value from equation is in base B).
1 <= A.size() <= 106
2 <= A[i] <= 106
2 <= B <= 9
First argument is a vector of integers A.
Second argument is an integer B
Return a single integer showing maximum pair functional value.
Input 1:
10 1 2 3 4 5 6 7 8 9 10 3
Input 2:
5 10 99 88 48 213 7
Output 1:
19
Output 2:
312
Explanation 1:
93 = 100 and 103 = 101 Hence, F(9,10,3) = 2013 = 1910 We may check for other pairs we will get less than or equal to 15.
Explanation 2:
Lets calculate F(i,j,7) for all pairs, 10 99: 109 10 88: 91 10 48: 2 10 213: 223 99 88: 187 99 48: 140 99 213: 312 88 48: 80 88 213: 245 48 213: 205 Clearly maximum value is 312.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.