fork(1) download
  1. // https://c...content-available-to-author-only...u.vn/student/question/DSA04004
  2. // GẤP ĐÔI DÃY SỐ
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. vector<long long> f(55);
  8. void prepare() {
  9. f[1] = 1;
  10. for (int i = 2; i < f.size(); ++i) {
  11. f[i] = f[i - 1] * 2;
  12. }
  13. }
  14.  
  15. void testCase() {
  16. long long n, k;
  17. cin >> n >> k;
  18. for (int i = n; i >= 1; --i) {
  19. if (k > f[i]) k -= f[i];
  20. else if (k == f[i]) {
  21. cout << i;
  22. return;
  23. }
  24. }
  25. }
  26.  
  27. int main() {
  28. ios_base::sync_with_stdio(false);
  29. cin.tie(NULL); cout.tie(NULL);
  30.  
  31. prepare();
  32. int T = 1; cin >> T;
  33. while (T--) {
  34. testCase();
  35. cout << "\n";
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5320KB
stdin
3
50 10 
50 11
50 12
stdout
2
1
3