fork download
  1. import java.util.*;
  2. import java.io.*;
  3. class Q2
  4. {
  5. public static void main(String args[])
  6. {
  7. Scanner d=new Scanner(System.in);
  8. int i,j,t;
  9. long x,n;
  10. char ch;
  11. t=d.nextInt();
  12. for(i=0;i<t;i++)
  13. {
  14. long temp=0L,d1,small;
  15. n=d.nextLong();
  16. x=d.nextLong();
  17. for(j=1;x>temp;j++)
  18. temp=temp+(9*((long)Math.pow(10,j-1))*j);
  19. --j;
  20. temp-=9*(long)Math.pow(10,j-1)*j;
  21. x=x-temp;
  22. d1=x%j;
  23. x=x/j;
  24. small=(long)Math.pow(10,j-1);
  25. if(j==1)
  26. System.out.println(x);
  27. else
  28. {
  29. small+=x;
  30. String s="";
  31. s=Long.toString(small);
  32. ch=s.charAt((int)d1-1);
  33. System.out.println(ch);
  34. }
  35. }
  36. }
  37. }
Success #stdin #stdout 0.09s 380672KB
stdin
3
10 5
100 100
10000000 100000067
stdout
5
5
3