public static int solve ( int n , int k ) {
  int start = 1 ;
  int end = ( int ) 1e9 ;
  int middle ;
  while ( start <= end ) {
    middle = ( start + end ) / 2 ;
    if ( fun1 ( middle , k ) == n ) {
      return middle ;
    }
    else if ( fun1 ( middle , k ) > n ) {
      if ( fun1 ( middle - 1 , k ) > n || fun1 ( middle - 1 , k ) == n ) {
        end = middle - 1 ;
      }
      else return middle ;
    }
    else start = middle + 1 ;
  }
  return - 1 ;
}

public static int solve ( int n , int k ) { int start = 1 ; int end = ( int ) 1e9 ; int middle ; while ( start <= end ) { middle = ( start + end ) / 2 ; if ( fun1 ( middle , k ) == n ) { return middle ; } else if ( fun1 ( middle , k ) > n ) { if ( fun1 ( middle - 1 , k ) > n || fun1 ( middle - 1 , k ) == n ) { end = middle - 1 ; } else return middle ; } else start = middle + 1 ; } return - 1 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (decimal_floating_point_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))) right: (identifier))) consequence: (block (return_statement (identifier))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) right: (identifier)) right: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) alternative: (return_statement (identifier)))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (return_statement (unary_expression operand: (decimal_integer_literal)))))