#include
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
long long n,base=1;
int step=0;
cin>>n;
while(base<=n)
base = (base<<1);
if(base>n)
{
base=(base>>1);
step=1+(n-base);
}
cout<<step<<endl;
}
return 0;
}
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
long long n,base=1;
int step=0;
cin>>n;
while(base<=n)
base = (base<<1);
if(base>n)
{
base=(base>>1);
step=1+(n-base);
}
cout<<step<<endl;
}
return 0;
}
also do check out this video editorial by prateek bhiaya.
i m checking no. at which base of 2 is greater than the n. if its greater then base power will be divided by 2(current base). nd total step = 1+ (n-currentbase)
@army_100
ok now after that u can again break (n-currentbase) in powers of 2 which will reduce ur number of moves.
pls once watch the video solution i have shared.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.