fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int t;
  5. cin >> t;
  6. while(t--){
  7. int n,k;
  8. cin >> n >> k;
  9. if(n%2==0){
  10. if(k%n==0) cout << n << '\n';
  11. else cout << k%n << '\n';
  12. continue;
  13. }
  14. int t1 = k, t2 = n/2;
  15. if(t2==1) t2=2;
  16. if(n>3) t1=k-1;
  17. int r = t1%t2,d;
  18. d = t1/t2;
  19. k += d;
  20. while(d+r>=t2){
  21. r = (d+r)%t2;
  22. d = (d+r)/t2;
  23. k += d;
  24. }
  25. if(k%n==0) cout << n << '\n';
  26. else cout << k%n << '\n';
  27. }
  28. }
Success #stdin #stdout 0.01s 5296KB
stdin
1
3 3
5 5
69 1337
stdout
1