My issue
why mode code is giving wrong answer even i think this should also solve all the testcases:
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
long long int x;
cin>>x;
if(x == 0 || x==2 || x==4)cout<<0<<endl;
else{
long long int temp = 2;
while(temp < x){
temp *= 2;
}
cout<<x-(temp-x)<<endl;
}
}
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
long long int x;
cin>>x;
if(x == 0 || x==2 || x==4)cout<<0<<endl;
else{
long long int temp = 2;
while(temp < x){
temp *= 2;
}
cout<<x-(temp-x)<<endl;
}
}
}
Problem Link: Chef loves Pizza Chef loves halfs Practice Coding Problem