Jump to content

Twin primes: Difference between revisions

C++ program allows limits to be specified on command line
(Rust program allows limits to be specified on command line)
(C++ program allows limits to be specified on command line)
Line 104:
<lang cpp>#include <cstdint>
#include <iostream>
#include <string>
#include <primesieve.hpp>
 
void print_twin_prime_count(uint64_t limit) {
int main() {
std::cout << "Number of twin prime pairs less than " << limit
<< " is " << primesieve::count_twins(0, limit - 1) << '\n';
}
 
int main(int argc, char** argv) {
std::cout.imbue(std::locale(""));
uint64_tif limit(argc => 10;1) {
// print number of twin prime pairs less than limits specified
for (int power = 1; power < 12; ++power, limit *= 10) {
// on the command line
std::cout << "Number of twin prime pairs less than " << limit
for (int i = <<1; "i is " << primesieve::count_twins(0,argc; limit++i) << '\n';{
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;
for (int power = 1; power < 12; ++power, limit *= 10) {
print_twin_prime_count(limit);
}
return 0;
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.