Use binary search to find the element after k + 1 multiples of x so that we get the answer bu subtracting
int a2 = Math . Max ( ( d + k + 1 ) * x , a [ i ] ) ; int it2 = Array . BinarySearch ( a , a2 ) ;