fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int T,B,len;
  6. unsigned long long X,aux;
  7.  
  8. int main() {
  9. cin>>T;
  10. while(T--){
  11. cin>>B>>X;
  12. for(int i=1;true;i++){
  13. aux = pow(B,i)*i;
  14. if(X>aux)
  15. X-=aux;
  16. else{
  17. len=i;
  18. break;
  19. }
  20. }
  21. cout<<X<<" "<<len<<endl;
  22. int c = X/len;
  23. int r = X%len;
  24. cout<<c<<" "<<r<<endl;
  25. int digit;
  26. string sd,ans;
  27.  
  28. while (c != 0){
  29. digit = c % B;
  30. if (digit < 10)
  31. sd = '0' + digit;
  32. else
  33. sd = digit - 10 + 'A';
  34. ans = sd + ans;
  35. c /= B;
  36. }
  37. cout<<ans<<endl;
  38. cout<<(char)(ans[r]+'a'-'0')<<endl;
  39.  
  40. }
  41. }
Success #stdin #stdout 0s 4524KB
stdin
6
4 5
4 3
2 32
26 24
26 50
4 27
stdout
1 2
0 1

G
3 1
3 0
3
d
22 3
7 1
111
b
24 1
24 0
O
�
24 2
12 0
C
t
23 2
11 1
23
d