# Sieve of Sundaram

This topic is 3162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've recently become interested in prime number sieves. The Sieve of Eratosthenes is simple, but I'm having quite a hard time understanding some of the other ones, especially the Sieve of Sundaram. Does anyone have/know of any example code for the algorithm, to help me understand how it works? I'd prefer Java or C++ if possible - all I've found so far has been Python, and I don't speak Python.

##### Share on other sites
include <iostream>#include <vector>int const N = 100; // Generate the primes up to 2*Nint main() {  std::vector<bool> l(N,true);  for (int j=1;;++j) {    int k=1+3*j;    if (k>=N)      break;    do {      l[k] = false;      k += 2*j+1;    } while (k<N);  }  for (int i=1; i<N; ++i) {    if (l)      std::cout << (2*i+1) << '\n';  }}

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009716
• ### Who's Online (See full list)

There are no registered users currently online

×