static long ans ( long n , long s ) {
  if ( n < s ) {
    return - 1 ;
  }
  else if ( n == s ) {
    return n + 1 ;
  }
  else {
    List < Long > divisor = new ArrayList < Long > ( ) ;
    for ( long i = 1 ;
    i <= Math . sqrt ( n - s ) ;
    i ++ ) {
      if ( digitSum ( n , i + 1 ) == s ) {
        return i + 1 ;
      }
      if ( ( n - s ) % i == 0 ) {
        divisor . add ( i ) ;
      }
    }
    Collections . reverse ( divisor ) ;
    for ( Long l : divisor ) {
      if ( digitSum ( n , ( n - s ) / l + 1 ) == s ) {
        return ( n - s ) / l + 1 ;
      }
    }
    return - 1 ;
  }
}

static long ans ( long n , long s ) { if ( n < s ) { return - 1 ; } else if ( n == s ) { return n + 1 ; } else { List < Long > divisor = new ArrayList < Long > ( ) ; for ( long i = 1 ; i <= Math . sqrt ( n - s ) ; i ++ ) { if ( digitSum ( n , i + 1 ) == s ) { return i + 1 ; } if ( ( n - s ) % i == 0 ) { divisor . add ( i ) ; } } Collections . reverse ( divisor ) ; for ( Long l : divisor ) { if ( digitSum ( n , ( n - s ) / l + 1 ) == s ) { return ( n - s ) / l + 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 (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (return_statement (unary_expression operand: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (return_statement (binary_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (identifier))) consequence: (block (return_statement (binary_expression left: (identifier) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)) right: (decimal_integer_literal)))) right: (identifier))) consequence: (block (return_statement (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)) right: (decimal_integer_literal))))))) (return_statement (unary_expression operand: (decimal_integer_literal))))))))