Twin primes: Difference between revisions

Content added Content deleted
(→‎{{header|ALGOL 68}}: Revised task requirements - check for primes less than the specified number)
m (C++ - handle limit <= 0)
Line 105: Line 105:
#include <primesieve.hpp>
#include <primesieve.hpp>


void print_twin_prime_count(uint64_t limit) {
void print_twin_prime_count(long long limit) {
std::cout << "Number of twin prime pairs less than " << limit
std::cout << "Number of twin prime pairs less than " << limit
<< " is " << primesieve::count_twins(0, limit - 1) << '\n';
<< " is " << (limit > 0 ? primesieve::count_twins(0, limit - 1) : 0) << '\n';
}
}


Line 117: Line 117:
for (int i = 1; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
try {
try {
print_twin_prime_count(std::stoull(argv[i]));
print_twin_prime_count(std::stoll(argv[i]));
} catch (const std::exception& ex) {
} catch (const std::exception& ex) {
std::cerr << "Cannot parse limit from '" << argv[i] << "'\n";
std::cerr << "Cannot parse limit from '" << argv[i] << "'\n";