public static long solver ( long N ) {
  if ( N < 0 ) {
    return 0 ;
  }
  long ans = 0 ;
  while ( true ) {
    int first = Character . getNumericValue ( String . valueOf ( N ) . charAt ( 0 ) ) ;
    int k = String . valueOf ( N ) . length ( ) - 1 ;
    if ( k == 0 ) {
      for ( int i = 0 ;
      i <= first ;
      i ++ ) {
        if ( i == 4 || i == 9 ) {
          ans ++ ;
        }
      }
      break ;
    }
    else {
      long ansTmp = first * ( long ) Math . pow ( 10.0 , k ) ;
      for ( int i = 0 ;
      i < first ;
      i ++ ) {
        if ( i == 4 || i == 9 ) {
          continue ;
        }
        ansTmp -= ( long ) Math . pow ( 8 , k ) ;
      }
      ans += ansTmp ;
    }
    if ( k > 0 && ( first == 4 || first == 9 ) ) {
      ans += N - first * ( long ) Math . pow ( 10 , k ) + 1 ;
      break ;
    }
    else {
      N %= first * ( long ) Math . pow ( 10.0 , k ) ;
    }
  }
  return ans ;
}

public static long solver ( long N ) { if ( N < 0 ) { return 0 ; } long ans = 0 ; while ( true ) { int first = Character . getNumericValue ( String . valueOf ( N ) . charAt ( 0 ) ) ; int k = String . valueOf ( N ) . length ( ) - 1 ; if ( k == 0 ) { for ( int i = 0 ; i <= first ; i ++ ) { if ( i == 4 || i == 9 ) { ans ++ ; } } break ; } else { long ansTmp = first * ( long ) Math . pow ( 10.0 , k ) ; for ( int i = 0 ; i < first ; i ++ ) { if ( i == 4 || i == 9 ) { continue ; } ansTmp -= ( long ) Math . pow ( 8 , k ) ; } ans += ansTmp ; } if ( k > 0 && ( first == 4 || first == 9 ) ) { ans += N - first * ( long ) Math . pow ( 10 , k ) + 1 ; break ; } else { N %= first * ( long ) Math . pow ( 10.0 , k ) ; } } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (true)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (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: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (update_expression (identifier))))))) (break_statement)) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_floating_point_literal) (identifier))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (continue_statement))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))))) right: (decimal_integer_literal)))) (break_statement)) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_floating_point_literal) (identifier))))))))))) (return_statement (identifier))))