static int longestCommon ( int n , int m ) {
  int mx = - Integer . MAX_VALUE ;
  String s1 = Integer . toBinaryString ( n ) ;
  String s2 = Integer . toBinaryString ( m ) ;
  String res = null ;
  int len = s1 . length ( ) ;
  int l = len ;
  while ( len > 0 ) {
    for ( int i = 0 ;
    i < l - len + 1 ;
    i ++ ) {
      String temp = s1 . substring ( i , i + len ) ;
      int tlen = temp . length ( ) ;
      if ( tlen > mx && s2 . contains ( temp ) ) {
        res = temp ;
        mx = tlen ;
      }
    }
    len = len - 1 ;
  }
  if ( res == "" ) return - 1 ;
  return Integer . parseInt ( res , 2 ) ;
}

static int longestCommon ( int n , int m ) { int mx = - Integer . MAX_VALUE ; String s1 = Integer . toBinaryString ( n ) ; String s2 = Integer . toBinaryString ( m ) ; String res = null ; int len = s1 . length ( ) ; int l = len ; while ( len > 0 ) { for ( int i = 0 ; i < l - len + 1 ; i ++ ) { String temp = s1 . substring ( i , i + len ) ; int tlen = temp . length ( ) ; if ( tlen > mx && s2 . contains ( temp ) ) { res = temp ; mx = tlen ; } } len = len - 1 ; } if ( res == " " ) return - 1 ; return Integer . parseInt ( res , 2 ) ; }
(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: (unary_expression operand: (field_access object: (identifier) field: (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (null_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (string_literal))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal)))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal))))))