思路:
构造。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll sum[33]; 5 int main() 6 { 7 int cnt = 0; 8 for (int i = 1; i <= 32; i++) 9 { 10 sum[i] = (sum[i - 1] + (1ll << cnt)); 11 cnt += 2; 12 } 13 int t; 14 ll n, k; 15 cin >> t; 16 while (t--) 17 { 18 cin >> n >> k; 19 if (n >= 32) { cout << "YES " << n - 1 << endl; continue; } 20 if (n == 1) 21 { 22 if (k == 1) cout << "YES 0" << endl; 23 else cout << "NO" << endl; 24 continue; 25 } 26 ll minn = 0, d = 0, s1 = 1, s2 = 2; 27 bool flg = false; 28 int i = n - 1; 29 for ( ; i >= 0; i--) 30 { 31 minn += (1ll << s1) - 1; 32 s1++; 33 d += ((1ll << s2) - 3) * sum[i]; 34 s2++; 35 ll maxn = minn + d; 36 if (k >= minn && k <= maxn) { flg = true; break; } 37 } 38 if (flg) cout << "YES " << i << endl; 39 else cout << "NO" << endl; 40 } 41 return 0; 42 }