sieve-of-atkin

C#: How to make Sieve of Atkin incremental

非 Y 不嫁゛ 提交于 2019-11-27 09:22:35
I don't know if this is possible or not, but I just gotta ask. My mathematical and algorithmic skills are kind of failing me here :P The thing is I now have this class that generates prime numbers up to a certain limit: 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 (ulong x = 1; x <= sqrt; x++) for (ulong y = 1; y <= sqrt; y++) { var n = 4*x*x + y*y; if (n <=

The Sieve of Atkin

非 Y 不嫁゛ 提交于 2019-11-26 22:33:43
I have been trying to learn algorithms for generating prime numbers and I came across Sieve of Atkin on Wikipedia. I understand almost all parts of the algorithm, except a few. Here are the questions: How are the three quadratic equations below formed? 4x^2+y^2, 3x^2+y^2 and 3x^2-y2 The algorithm in wikipedia talks about modulo sixty but I dont understand how/where that is used in the psudocode below. How are these reminders 1,5,7 and 11 found? Below is the pseudocode from Wikipedia for reference: // arbitrary search limit limit ← 1000000 // initialize the sieve for i in [5, limit]: is_prime(i

C#: How to make Sieve of Atkin incremental

空扰寡人 提交于 2019-11-26 14:25:45
问题 I don't know if this is possible or not, but I just gotta ask. My mathematical and algorithmic skills are kind of failing me here :P The thing is I now have this class that generates prime numbers up to a certain limit: 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)

The Sieve of Atkin

点点圈 提交于 2019-11-26 08:24:10
问题 I have been trying to learn algorithms for generating prime numbers and I came across Sieve of Atkin on Wikipedia. I understand almost all parts of the algorithm, except a few. Here are the questions: How are the three quadratic equations below formed? 4x^2+y^2, 3x^2+y^2 and 3x^2-y2 The algorithm in wikipedia talks about modulo sixty but I dont understand how/where that is used in the psudocode below. How are these reminders 1,5,7 and 11 found? Below is the pseudocode from Wikipedia for