/****************************************************************************** * This program computes the number of primes function π(x) * using an estimate formula. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace Utils; using namespace std; long π(int x) noexcept { return floor(x / (log(x) - 1.0) + 0.5); } int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); int x = 10; for (int i = 2; i <= 9; ++i) { x *= 10; wcout << fmt::format(L"π({0:d}) = {1:d}", x, π(x)) << endl; } return 0; }