#include <iostream>
#include <limits>
#include <cstdint>
template<class T>
int GetBitDigit(const T& N){
if (N == 0) return 0;
for (std::size_t i = 0; i < std::numeric_limits<T>::digits; i++){
if ((N >> i) == 0) return i;
}
return -1;
}
std::uint64_t MakeBitOnArray(std::size_t N){
std::uint64_t Num = 0;
for (std::size_t i = 0; i < N; i++){
Num <<= 1;
Num |= 1;
}
return Num;
}
std::uint64_t MakeHoge(std::uint64_t N){
auto D = GetBitDigit(N);
auto B = MakeBitOnArray(D);
auto R = N^B;
return R & B;
}
int main(){
std::uint64_t N = 0;
std::uint64_t A = 0;
N = 1;
A = MakeHoge(N);
std::cout << N << "->" << A <<std::endl;
N = 12345;
A = MakeHoge(N);
std::cout << N << "->" << A <<std::endl;
N = 256;
A = MakeHoge(N);
std::cout << N << "->" << A <<std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzPgojaW5jbHVkZSA8Y3N0ZGludD4KCnRlbXBsYXRlPGNsYXNzIFQ+CmludCBHZXRCaXREaWdpdChjb25zdCBUJiBOKXsKCWlmIChOID09IDApIHJldHVybiAwOwoJZm9yIChzdGQ6OnNpemVfdCBpID0gMDsgaSA8IHN0ZDo6bnVtZXJpY19saW1pdHM8VD46OmRpZ2l0czsgaSsrKXsKCQlpZiAoKE4gPj4gaSkgPT0gMCkgcmV0dXJuIGk7Cgl9CglyZXR1cm4gLTE7Cn0KCnN0ZDo6dWludDY0X3QgTWFrZUJpdE9uQXJyYXkoc3RkOjpzaXplX3QgTil7CglzdGQ6OnVpbnQ2NF90IE51bSA9IDA7Cglmb3IgKHN0ZDo6c2l6ZV90IGkgPSAwOyBpIDwgTjsgaSsrKXsKCQlOdW0gPDw9IDE7CgkJTnVtIHw9IDE7Cgl9CglyZXR1cm4gTnVtOwp9CgpzdGQ6OnVpbnQ2NF90IE1ha2VIb2dlKHN0ZDo6dWludDY0X3QgTil7CglhdXRvIEQgPSBHZXRCaXREaWdpdChOKTsKCWF1d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