static long solve ( long N , long offset , long start , int digits ) {
  long thisSection = digits * start * 9 ;
  long fromOffset = N - offset ;
  if ( fromOffset > thisSection ) {
    return solve ( N , offset + thisSection , 10 * start , digits + 1 ) ;
  }
  long number = start + ( fromOffset - 1 ) / digits ;
  long posInNumber = digits - 1 - ( fromOffset - 1 ) % digits ;
  while ( posInNumber > 0 ) {
    posInNumber -- ;
    number /= 10 ;
  }
  return number % 10 ;
}

static long solve ( long N , long offset , long start , int digits ) { long thisSection = digits * start * 9 ; long fromOffset = N - offset ; if ( fromOffset > thisSection ) { return solve ( N , offset + thisSection , 10 * start , digits + 1 ) ; } long number = start + ( fromOffset - 1 ) / digits ; long posInNumber = digits - 1 - ( fromOffset - 1 ) % digits ; while ( posInNumber > 0 ) { posInNumber -- ; number /= 10 ; } return number % 10 ; }
(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)) (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: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (return_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)) (binary_expression left: (decimal_integer_literal) right: (identifier)) (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (return_statement (binary_expression left: (identifier) right: (decimal_integer_literal)))))