D. 答案最多20次,枚举前面几次+1就行。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve(){
ll n;
cin >> n;
ll y = 1 << 20, ans=20;
for (int i = 0; i <= 20; ++i) {
ll g = 0,N = n + i;
while (N % y != 0) N <<= 1, g++;
ans = min(ans, i + g);
}
cout << ans << "\n";
}
int main() {
int T;
cin >>T;
while(T--)solve();
return 0;
}