File: primesieve_iterator.cpp

package info (click to toggle)
primesieve 7.6%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 832 kB
  • sloc: cpp: 6,751; ansic: 455; sh: 197; makefile: 87
file content (27 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// @example 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;
}