fork(5) download
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. public class Main {
  5.  
  6. public static void main( final String[] args ) throws Exception {
  7. final long n = Long.parseLong( br.readLine() );
  8. System.out.println( solve( n ) );
  9. }
  10.  
  11. public static char solve( final long n ) {
  12. if ( n < 10 ) {
  13. return (char)( '0' + n );
  14. } else {
  15. return part( n - 10, 2 );
  16. }
  17. }
  18.  
  19. private static char part( final long nth, final int digCount ) {
  20. if ( nth == 0 ) return '1';
  21. long pow = 1;
  22. for ( int i = 1; i < digCount; ++i ) {
  23. pow *= 10;
  24. }
  25. final long firstInPart = pow;
  26. final long partSize = digCount * 9 * pow;
  27. if ( nth > partSize ) { // skip that part
  28. return part( nth - partSize, digCount + 1 );
  29. }
  30. final long number = nth / digCount;
  31. final long digitIndex = nth % digCount;
  32. return Long.toString( firstInPart + number ).charAt( (int)digitIndex );
  33. }
  34.  
  35. }
  36.  
Success #stdin #stdout 0.07s 380160KB
stdin
1393
stdout
5