一,思路:
这题只要我们求得最后 1的位置,那么我们就只关注 1是怎么进行交换的。通过分析知道 1只能被--->(2,4,8,16,32)进行交换,这样我们可以直接暴力枚举了,最大也就 32次(2^32 大概是 1e9级别)。具体看代码。
二,代码
#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
void Sovle() {
int n;
cin>>n;
//直接暴力枚举,也可以二分做
ll x=1;
while(true){
x*=2;
if(x>n) break;
}
cout<<x/2<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
Sovle();
}
return 0;
}