fork download
  1. #include <stdio.h>
  2.  
  3. char findChar(int B, int width, unsigned long pos) {
  4. if(pos==0)
  5. return B + 'a' - 1;
  6.  
  7. /*if(pos<=B)
  8. return pos + 'a' - 1;
  9. */
  10.  
  11. unsigned long streamlength = 1;
  12. for(int i=1; i<=width; i++) {
  13. streamlength = streamlength * B;
  14. }
  15. streamlength = streamlength * width;
  16. printf("streamlength %lu\n", streamlength);
  17. return '?';
  18. }
  19.  
  20. char solve(int B, unsigned long X) {
  21. if (B==1) return 'a';
  22. unsigned long sum = 0, term=1, pos=0;
  23. int width=1;
  24. while(1) {
  25. term = term * B;
  26. if (sum + term * width <= X)
  27. sum = sum + term * width;
  28. else {
  29. pos = X-sum;
  30. break;
  31. }
  32. width++;
  33. }
  34. printf("%d %lu %d %lu %lu\n", B, X, width, pos, sum);
  35.  
  36. return findChar(B, width, pos);
  37. }
  38.  
  39. int main() {
  40. int T, B, X;
  41. scanf("%d", &T);
  42. for(int i=1; i<=T; i++) {
  43. scanf("%d %d", &B, &X);
  44. printf("%c\n", solve(B, X+1));
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 4524KB
stdin
1
2 32
stdout
2 33 3 23 10
streamlength 24
?