sieve-of-atkin

Segmented Sieve of Atkin, possible?

て烟熏妆下的殇ゞ 提交于 2020-01-11 03:07:35
问题 I am aware of the fact that the Sieve of Eratosthenes can be implemented so that it finds primes continuosly without an upper bound (the segmented sieve). My question is, could the Sieve of Atkin/Bernstein be implemented in the same way? Related question: C#: How to make Sieve of Atkin incremental However the related question has only 1 answer, which says "It's impossible for all sieves", which is obviously incorrect. 回答1: Atkin/Bernstein give a segmented version in Section 5 of their

Calculating sum of prime number below 2 million by using Sieve of Atkin

喜你入骨 提交于 2019-12-25 02:53:53
问题 I'm doing project Euler and I got this problem. I run the code in VS 2013 and the program crashes because of overflow. This is my method: void problem10() { long long int iter = 2, sum = 0; //Sieve of Atkin bool isPrime[PRIME_LIMIT+1]; for (long long int i = 5; i <= PRIME_LIMIT; i++) { isPrime[i] = false; } long long int lim = ceil(sqrt(PRIME_LIMIT)); for (long long int x = 1; x <= lim; x++) { for (long long int y = 1; y <= lim; y++) { long long int n = 4 * x*x + y*y; if (n <= PRIME_LIMIT &&

C#: Implementation of the Sieve of Atkin

泪湿孤枕 提交于 2019-12-20 10:48:11
问题 I was wondering if someone here have a good implementation of the Sieve of Atkin that they would like to share. I am trying to implement it, but can't quite wrap my head around it. Here is what I have so far. public class Atkin : IEnumerable<ulong> { private readonly List<ulong> primes; private readonly ulong limit; public Atkin(ulong limit) { this.limit = limit; primes = new List<ulong>(); } private void FindPrimes() { var isPrime = new bool[limit + 1]; var sqrt = Math.Sqrt(limit); for

Sieve of Atkin - Explanation and Java example

徘徊边缘 提交于 2019-12-17 21:45:07
问题 I have read about Sieve of Atkin on Wikipedia but the wiki is limited at the moment. I was looking for an explanation of Sieve of Atkin at a high level and an example in Java. Thanks. 回答1: You may (and probably do) know some of the basic ideas given here about prime numbers, composite numbers and sieves, but they may benefit other readers in understanding the nature of the algorithm. Some of this answer gets dangerously close to belonging on the math equivalent of StackOverflow, but I feel

C++ Sieve of Atkin overlooks a few prime numbers

霸气de小男生 提交于 2019-12-09 19:37:46
问题 Recently I've been working on a C++ prime generator that uses the Sieve of Atkin ( http://en.wikipedia.org/wiki/Sieve_of_atkin ) to generate its primes. My objective is to be able to generate any 32-bit number. I'll use it mostly for project euler problems. mostly it's just a summer project. The program uses a bitboard to store primality: that is, a series of ones and zeros where for example the 11th bit would be a 1, the 12th a 0, and the 13th a 1, etc. For efficient memory usage, this is

C++ Sieve of Atkin overlooks a few prime numbers

无人久伴 提交于 2019-12-04 13:43:15
Recently I've been working on a C++ prime generator that uses the Sieve of Atkin ( http://en.wikipedia.org/wiki/Sieve_of_atkin ) to generate its primes. My objective is to be able to generate any 32-bit number. I'll use it mostly for project euler problems. mostly it's just a summer project. The program uses a bitboard to store primality: that is, a series of ones and zeros where for example the 11th bit would be a 1, the 12th a 0, and the 13th a 1, etc. For efficient memory usage, this is actually and array of chars, each char containing 8 bits. I use flags and bitwise-operators to set and

Segmented Sieve of Atkin, possible?

社会主义新天地 提交于 2019-12-01 05:40:38
I am aware of the fact that the Sieve of Eratosthenes can be implemented so that it finds primes continuosly without an upper bound (the segmented sieve). My question is, could the Sieve of Atkin/Bernstein be implemented in the same way? Related question: C#: How to make Sieve of Atkin incremental However the related question has only 1 answer, which says "It's impossible for all sieves", which is obviously incorrect. Atkin/Bernstein give a segmented version in Section 5 of their original paper . Presumably Bernstein's primegen program uses that method. GordonBGood In fact, one can implement

Sieve of Atkin explanation

蓝咒 提交于 2019-11-30 11:27:13
问题 I am doing a project at the moment and I need an efficient method for calculating prime numbers. I have used the sieve of Eratosthenes but, I have been searching around and have found that the sieve of Atkin is a more efficient method. I have found it difficult to find an explanation (that I have been able to understand!) of this method. How does it work? Example code (preferably in C or python) would be brilliant. Edit: thanks for your help, the only thing that I still do not understand is

Sieve of Atkin explanation

耗尽温柔 提交于 2019-11-30 01:45:36
I am doing a project at the moment and I need an efficient method for calculating prime numbers. I have used the sieve of Eratosthenes but, I have been searching around and have found that the sieve of Atkin is a more efficient method. I have found it difficult to find an explanation (that I have been able to understand!) of this method. How does it work? Example code (preferably in C or python) would be brilliant. Edit: thanks for your help, the only thing that I still do not understand is what the x and y variables are referring to in the pseudo code. Could someone please shed some light on

Sieve of Atkin - Explanation and Java example

跟風遠走 提交于 2019-11-28 16:23:50
I have read about Sieve of Atkin on Wikipedia but the wiki is limited at the moment. I was looking for an explanation of Sieve of Atkin at a high level and an example in Java. Thanks. You may (and probably do) know some of the basic ideas given here about prime numbers, composite numbers and sieves, but they may benefit other readers in understanding the nature of the algorithm. Some of this answer gets dangerously close to belonging on the math equivalent of StackOverflow, but I feel some of it is necessary to make the connection between what the algorithm does and how it does it. The three