This seems to be the proper test for pentagonal numbers:
Code:#include <iostream> #include <cmath> typedef unsigned long ulong; bool checkPentagonal(ulong n) { double x = (sqrt(24.0 * n + 1) + 1) / 6; return floor(x) == x; } int main() { for (size_t i = 1; i < 2000; i++) if (checkPentagonal(i)) std::cout << i << '\n'; }