prev_prime.cpp

Iterate backwards over primes using primesieve::iterator.

#include <primesieve.hpp>
#include <iostream>
int main()
{
primesieve::iterator it;
it.skipto(2000);
uint64_t prime = it.prev_prime();
// iterate over primes from 2000 to 1000
for (; prime >= 1000; prime = it.prev_prime())
std::cout << prime << std::endl;
return 0;
}
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.
primesieve::iterator::prev_prime
uint64_t prev_prime()
Get the previous prime.
Definition: iterator.hpp:79