#include #include #include // The recurrence itself: T(0) = 0 and T(n) = 2T(n - 1) + 1. constexpr lets // the compiler run it, and no step on the way to 64 disks overflows. constexpr std::uint64_t minimum_moves(int n) { return n == 0 ? 0 : 2 * minimum_moves(n - 1) + 1; } // Checked while compiling: if either were false, this file would not build. static_assert(minimum_moves(3) == 7); static_assert(minimum_moves(64) == std::numeric_limits::max()); int main() { constexpr std::uint64_t moves = minimum_moves(64); std::cout << "64 disks: " << moves << " moves\n"; // Unsigned arithmetic wraps rather than overflowing: one move more is zero. std::cout << "one more: " << moves + 1 << '\n'; }