static void powerfulIntegers ( int x , int y , int bound ) {
  Set < Integer > s = new HashSet < > ( ) ;
  ArrayList < Integer > powersOfY = new ArrayList < > ( ) ;
  int i ;
  powersOfY . add ( 1 ) ;
  for ( i = y ;
  i < bound ;
  i = i * y ) powersOfY . add ( i ) ;
  i = 0 ;
  while ( true ) {
    int xPowI = ( int ) Math . pow ( ( double ) x , ( double ) i ) ;
    if ( xPowI >= bound ) break ;
    for ( int j = 0 ;
    j < powersOfY . size ( ) ;
    ++ j ) {
      int num = xPowI + powersOfY . get ( j ) ;
      if ( num <= bound ) s . add ( num ) ;
      else break ;
    }
    i ++ ;
  }
  Iterator itr = s . iterator ( ) ;
  while ( itr . hasNext ( ) ) {
    System . out . print ( itr . next ( ) + " " ) ;
  }
}

static void powerfulIntegers ( int x , int y , int bound ) { Set < Integer > s = new HashSet < > ( ) ; ArrayList < Integer > powersOfY = new ArrayList < > ( ) ; int i ; powersOfY . add ( 1 ) ; for ( i = y ; i < bound ; i = i * y ) powersOfY . add ( i ) ; i = 0 ; while ( true ) { int xPowI = ( int ) Math . pow ( ( double ) x , ( double ) i ) ; if ( xPowI >= bound ) break ; for ( int j = 0 ; j < powersOfY . size ( ) ; ++ j ) { int num = xPowI + powersOfY . get ( j ) ; if ( num <= bound ) s . add ( num ) ; else break ; } i ++ ; } Iterator itr = s . iterator ( ) ; while ( itr . hasNext ( ) ) { System . out . print ( itr . next ( ) + " ▁ " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (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)) arguments: (argument_list)))) (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)) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (for_statement init: (assignment_expression left: (identifier) right: (identifier)) condition: (binary_expression left: (identifier) right: (identifier)) update: (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (true)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (cast_expression type: (floating_point_type) value: (identifier)) (cast_expression type: (floating_point_type) value: (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (break_statement)) (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))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) alternative: (break_statement)))) (expression_statement (update_expression (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (string_literal)))))))))