Help me in solving CHEFIZZA problem

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

your code will fail if x is power of 2
like for test case x=8,16,32
if x is power of 2 ans will be 0
you can check if x is power of 2 by ((x&(x-1))==0)