primesieve_iterator.cpp

Iterate over primes using primesieve::iterator.

#include <primesieve.hpp>
#include <iostream>
int main()
{
primesieve::iterator it;
uint64_t prime = it.next_prime();
uint64_t sum = 0;
// iterate over the primes below 10^9
for (; prime < 1000000000ull; prime = it.next_prime())
sum += prime;
std::cout << "Sum of the primes below 10^9 = " << sum << std::endl;
// generate primes > 1000
it.skipto(1000);
prime = it.next_prime();
for (; prime < 1100; prime = it.next_prime())
std::cout << prime << std::endl;
return 0;
}
primesieve::iterator::next_prime
uint64_t next_prime()
Get the next prime.
Definition: iterator.hpp:66
primesieve.hpp
primesieve C++ API. primesieve is a library for fast prime number generation, in case an error occurs...
primesieve::iterator
primesieve::iterator allows to easily iterate over primes both forwards and backwards.
Definition: iterator.hpp:32
primesieve::iterator::skipto
void skipto(uint64_t start, uint64_t stop_hint=get_max_stop())
Reset the primesieve iterator to start.