-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1110C.cpp
More file actions
39 lines (37 loc) · 732 Bytes
/
1110C.cpp
File metadata and controls
39 lines (37 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int invertBits(int num)
{
int x = log2(num) + 1;
for (int i = 0; i < x; i++)
num = (num ^ (1 << i));
return num;
//cout << num;
}
int main(){
int n;
cin>>n;
while(n--){
int k;
cin>>k;
int y=invertBits(k);
int x;
if(y==0){
int mx=0;
y=k;
while(y>0){
y--;
x=__gcd(k^y,k&y);
mx=max(mx,x);
y=y>>1;
//cout<<y<<"\n";
}
x=mx;
}
else{
x=__gcd(k^y,k&y);
}
cout<<x<<"\n";
}
}