-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
53 lines (51 loc) · 992 Bytes
/
A.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long power(long long x,long long y)
{
long long u=1,i;
for(i=1;i<=y;i++)
u=u*x;
return u;
}
int main()
{
fastio;
long long t,n,i,ara[100],low,high,mid,count;
for(i=0;;i++)
{
if(power(2,i)-1>1e9)
{
count=i;
break;
}
else
ara[i]=power(2,i)-1;
}
cin>>t;
while(t--)
{
cin>>n;
if(ara[count-1]<n)
{
cout<<ara[count-1]<<"\n";
continue;
}
low=0;
high=count-1;
while(low<=high)
{
mid=(low+high)/2;
if(ara[mid]<n && ara[mid+1]>=n)
{
cout<<ara[mid]<<"\n";
break;
}
else if(ara[mid]<n)
low=mid+1;
else
high=mid-1;
}
}
return 0;
}