#include <limits>
#include <iostream>
unsigned long long pow2( unsigned int n )
{
if( n >= std::numeric_limits<unsigned long long>::digits ) return 0 ;
unsigned long long result = 1 ;
// return result << n ;
for( unsigned int i=0; i<n; ++i )
{
result *= 2 ;
}
return result;
}
int main()
{
for( unsigned int n = 0 ; n < 128; ++n )
{
unsigned long long result = pow2(n) ;
if( result > 0 ) std::cout << "2^" << n << " == " << result << '\n' ;
else
{
std::cerr << "the number 2^" << n
<< " is too big to be represented by an unsigned long long\n" ;
return 0 ;
}
}
}
I2luY2x1ZGUgPGxpbWl0cz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdW5zaWduZWQgbG9uZyBsb25nIHBvdzIoIHVuc2lnbmVkIGludCBuICkKewogICAgaWYoIG4gPj0gc3RkOjpudW1lcmljX2xpbWl0czx1bnNpZ25lZCBsb25nIGxvbmc+OjpkaWdpdHMgKSByZXR1cm4gMCA7CgogICAgdW5zaWduZWQgbG9uZyBsb25nIHJlc3VsdCA9IDEgOwoKICAgIC8vIHJldHVybiByZXN1bHQgPDwgbiA7CgogICAgZm9yKCB1bnNpZ25lZCBpbnQgaT0wOyBpPG47ICsraSApCiAgICB7CiAgICAgICAgcmVzdWx0ICo9IDIgOwogICAgfQoKICAgIHJldHVybiByZXN1bHQ7Cn0KCmludCBtYWluKCkKewogICAgZm9yKCB1bnNpZ25lZCBpbnQgbiA9IDAgOyBuIDwgMTI4OyArK24gKQogICAgewogICAgICAgIHVuc2lnbmVkIGxvbmcgbG9uZyByZXN1bHQgPSBwb3cyKG4pIDsKCiAgICAgICAgaWYoIHJlc3VsdCA+IDAgKSBzdGQ6OmNvdXQgPDwgIjJeIiA8PCBuIDw8ICIgPT0gIiA8PCByZXN1bHQgPDwgJ1xuJyA7CgogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHN0ZDo6Y2VyciA8PCAidGhlIG51bWJlciAyXiIgPDwgbgogICAgICAgICAgICAgICAgICAgICAgIDw8ICIgaXMgdG9vIGJpZyB0byBiZSByZXByZXNlbnRlZCBieSBhbiB1bnNpZ25lZCBsb25nIGxvbmdcbiIgOwogICAgICAgICAgICByZXR1cm4gMCA7CiAgICAgICAgfQogICAgfQp9Cg==