private static BigInteger solve ( BigInteger n , BigInteger m ) {
  if ( m . equals ( BigInteger . ONE ) ) return n ;
  n = n . subtract ( BigInteger . ONE ) ;
  m = m . subtract ( BigInteger . ONE ) ;
  BigInteger x , y , sumX , sumY ;
  y = n . shiftRight ( 1 ) ;
  x = n . subtract ( y ) ;
  sumX = sumY = BigInteger . ONE ;
  for ( ;
  m . compareTo ( sumX . add ( sumY ) ) > 0 ;
  ) {
    m = m . subtract ( sumX . add ( sumY ) ) ;
    x = x . subtract ( BigInteger . ONE ) ;
    y = y . subtract ( BigInteger . ONE ) ;
    BigInteger tx , ty , tSumX = sumX , tSumY = sumY ;
    tx = x . shiftRight ( 1 ) ;
    x = x . subtract ( tx ) ;
    ty = y . subtract ( y . shiftRight ( 1 ) ) ;
    y = y . shiftRight ( 1 ) ;
    if ( tx . equals ( x ) ) {
      sumX = sumX . add ( tSumX ) ;
    }
    else {
      sumY = sumY . add ( tSumX ) ;
    }
    if ( ty . equals ( x ) ) {
      sumX = sumX . add ( tSumY ) ;
    }
    else {
      sumY = sumY . add ( tSumY ) ;
    }
  }
  return m . compareTo ( sumX ) <= 0 ? x : y ;
}

private static BigInteger solve ( BigInteger n , BigInteger m ) { if ( m . equals ( BigInteger . ONE ) ) return n ; n = n . subtract ( BigInteger . ONE ) ; m = m . subtract ( BigInteger . ONE ) ; BigInteger x , y , sumX , sumY ; y = n . shiftRight ( 1 ) ; x = n . subtract ( y ) ; sumX = sumY = BigInteger . ONE ; for ( ; m . compareTo ( sumX . add ( sumY ) ) > 0 ; ) { m = m . subtract ( sumX . add ( sumY ) ) ; x = x . subtract ( BigInteger . ONE ) ; y = y . subtract ( BigInteger . ONE ) ; BigInteger tx , ty , tSumX = sumX , tSumY = sumY ; tx = x . shiftRight ( 1 ) ; x = x . subtract ( tx ) ; ty = y . subtract ( y . shiftRight ( 1 ) ) ; y = y . shiftRight ( 1 ) ; if ( tx . equals ( x ) ) { sumX = sumX . add ( tSumX ) ; } else { sumY = sumY . add ( tSumX ) ; } if ( ty . equals ( x ) ) { sumX = sumX . add ( tSumY ) ; } else { sumY = sumY . add ( tSumY ) ; } } return m . compareTo ( sumX ) <= 0 ? x : y ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier))))) consequence: (return_statement (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))))) (for_statement condition: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (decimal_integer_literal)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (return_statement (ternary_expression condition: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal)) consequence: (identifier) alternative: (identifier)))))