for efficient searching , use binary search .
while ( start <= end ) { long long mid = ( start + end ) / 2 ; long long val = func ( a , b , c , mid ) ; if ( val == k ) { ans = mid ; break ; } else if ( val > k ) { end = mid - 1 ; } else { start = mid + 1 ; } } return ans ; }