Twin primes: Difference between revisions
Content added Content deleted
(Rust program allows limits to be specified on command line) |
(C++ program allows limits to be specified on command line) |
||
Line 104: | Line 104: | ||
<lang cpp>#include <cstdint> |
<lang cpp>#include <cstdint> |
||
#include <iostream> |
#include <iostream> |
||
#include <string> |
|||
#include <primesieve.hpp> |
#include <primesieve.hpp> |
||
void print_twin_prime_count(uint64_t limit) { |
|||
int main() { |
|||
⚫ | |||
<< " is " << primesieve::count_twins(0, limit - 1) << '\n'; |
|||
} |
|||
int main(int argc, char** argv) { |
|||
std::cout.imbue(std::locale("")); |
std::cout.imbue(std::locale("")); |
||
if (argc > 1) { |
|||
// print number of twin prime pairs less than limits specified |
|||
⚫ | |||
// on the command line |
|||
⚫ | |||
for (int i = 1; i < argc; ++i) { |
|||
try { |
|||
print_twin_prime_count(std::stoull(argv[i])); |
|||
} catch (const std::exception& ex) { |
|||
std::cerr << "Cannot parse limit from '" << argv[i] << "'\n"; |
|||
} |
|||
} |
|||
} else { |
|||
// if no limit was specified then show the number of twin prime |
|||
// pairs less than powers of 10 up to 100 billion |
|||
uint64_t limit = 10; |
|||
⚫ | |||
print_twin_prime_count(limit); |
|||
} |
} |
||
return 0; |
return 0; |