#include #include #include #include using namespace std; typedef unsigned long long BigNumT; const BigNumT LIMIT = static_cast(sqrtl(ULLONG_MAX)); string AddCommas(BigNumT x) { string withCommas; string tmp; int lastThree; while (x > 0) { // pull off the last three digits lastThree = static_cast(x % 1000); x /= 1000; // convert to a string and pad with 0 if necessary tmp = to_string(lastThree); while (tmp.size() < 3 and x > 0) { tmp = "0" + tmp; } // add this to the string, note "reverse" order withCommas = tmp + withCommas; // if there are still digits to be added, add a comma, again in "reverse" if (x > 0) { withCommas = "," + withCommas; } } return withCommas; } int main() { BigNumT x; cout << setw(15) << "n" ; cout << setw(8) << "log_2 n"; cout << setw(30) << "n^2"; cout << endl; cout << setfill('-'); cout << setw(15+8+30) << '-'; cout << endl; cout << setfill(' '); for(x = 1; x < LIMIT; x *= 2) { cout << setw(15) << AddCommas(x) ; cout << setw(8) << ceil(log2(x)); cout << setw(30) << AddCommas(x*x); cout << endl; } }