sieve

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

Haskell --> F#: Turner's Sieve

◇◆丶佛笑我妖孽 提交于 2019-11-30 05:17:38
I was reading on different sieving algorithms when I stumbled upon a kind of improved version of the Sieve of Eratosthenes called Euler's Sieve. According to Wikipedia there is an implementation of an slightly different version of the idea (called Turner's Sieve) in Haskell. Now I am trying to understand what exactly the code snippet given does and I think I've got it but now I wanted to translate the code into F# and have really no idea where to start. My main concern is that there doesn't seem to be a function to "substract" two sequences. Here's the code: import Data.OrdList (minus) primes

大数据最核心的关键技术——32个算法,记得收藏!

自闭症网瘾萝莉.ら 提交于 2019-11-29 16:25:33
奥地利符号计算研究所的Christoph Koutschan博士在自己的页面上发布了一篇文章,提到他做了一个调查,参与者大多数是计算机科学家,他请这些科学家投票选出最重要的算法,以下是这次调查的结果,按照英文名称字母顺序排序。 1、A* 搜索算法— 图形搜索算法——从给定起点到给定终点计算出路径。其中使用了一种启发式的估算,为每个节点估算通过该节点的最佳路径,并以之为各个地点排定次序。算法以得到的次序访问这些节点。因此,A*搜索算法是最佳优先搜索的范例。 2、集束搜索——最佳优先搜索算法的优化。使用启发式函数评估它检查的每个节点的能力。不过,集束搜索只能在每个深度中发现最前面的m个最符合条件的节点,m是固定数字——集束的宽度。 3、二分查找——在线性数组中找特定值的算法,每个步骤去掉一半不符合要求的数据。 4、分支界定算法——在多种最优化问题中寻找特定最优化解决方案的算法,特别是针对离散、组合的最优化。 5、Buchberger算法——一种数学算法,可将其视为针对单变量最大公约数求解的欧几里得算法和线性系统中高斯消元法的泛化。 6、数据压缩——采取特定编码方案,使用更少的字节数(或是其他信息承载单元)对信息编码的过程,又叫来源编码。 7、Diffie-Hellman密钥交换算法——一种加密协议,允许双方在事先不了解对方的情况下,在不安全的通信信道中,共同建立共享密钥

Sieve of Eratosthenes

淺唱寂寞╮ 提交于 2019-11-29 12:09:40
I read up on the sieve of Eratosthenes while solving a question on Project Euler . I'm sure you guys know which question im talking about. So here's the thing. My code manages to show all the primes under 1 million correctly. However when i try the same implementation for 2 million it's giving me a segmentation fault... I have a certain idea of why the error is coming but don't know how to correct it... Here's the code for primes under 1 million. #include<stdio.h> int main(void) { int i,k=2; int j; int n=1000000; int prime[2000000]={}; for(i=0;i<n;i++) // initializes the prime number array {

Implementing the Page Segmented Sieve of Eratosthenes in Javascript

牧云@^-^@ 提交于 2019-11-29 08:43:39
I recently read about a faster implementation of Segmented Sieve of Eratosthenes for really big numbers. Following is an implementation of the same: function sieve(low, high) { var primeArray = [], ll = Math.sqrt(low), output = []; for (var i = 0; i < high; i++) { primeArray[i] = true; } for (var i = 2; i <= ll; i++) { if (primeArray[i]) { for (var j = i * i; j < high; j += i) { primeArray[j] = false; } } } for (var i = 2; i < ll; i++) { if(primeArray[i]) { var segmentStart = Math.floor(low/i) * i; for(var j = segmentStart; j <= high; j+=i) { primeArray[j] = false; } } } for(var i = low; i <=

Haskell --> F#: Turner's Sieve

廉价感情. 提交于 2019-11-29 03:26:12
问题 I was reading on different sieving algorithms when I stumbled upon a kind of improved version of the Sieve of Eratosthenes called Euler's Sieve. According to Wikipedia there is an implementation of an slightly different version of the idea (called Turner's Sieve) in Haskell. Now I am trying to understand what exactly the code snippet given does and I think I've got it but now I wanted to translate the code into F# and have really no idea where to start. My main concern is that there doesn't

Is there a way to find the approximate value of the nth prime?

妖精的绣舞 提交于 2019-11-28 20:40:31
Is there a function which will return the approximate value of the n th prime? I think this would be something like an approximate inverse prime counting function. For example, if I gave this function 25 it would return a number around 100, or if I gave this function 1000 it would return a number around 8000. I don't care if the number returned is prime or not, but I do want it to be fast (so no generating the first n prime numbers to return the n th.) I would like this so that I can generate the first n prime numbers using a sieve ( Eratosthenes or Atkin ). Therefore, the approximation for n

Sieve of Eratosthenes

无人久伴 提交于 2019-11-28 05:07:33
问题 I read up on the sieve of Eratosthenes while solving a question on Project Euler. I'm sure you guys know which question im talking about. So here's the thing. My code manages to show all the primes under 1 million correctly. However when i try the same implementation for 2 million it's giving me a segmentation fault... I have a certain idea of why the error is coming but don't know how to correct it... Here's the code for primes under 1 million. #include<stdio.h> int main(void) { int i,k=2;

Sieve of Eratosthenes algorithm in C

前提是你 提交于 2019-11-27 06:31:22
问题 Okay, so this function I created uses the Sieve of Eratosthenes algorithm to compute all the primes <= n. This function stores the prime numbers and the count of primes in the parameters. When the function exits, primes should be pointing to a chunk of dynamically allocated memory that holds all the primes <= num. *count will have the count of primes. Here is my function getPrimes : void getPrimes(int num, int* count, int** array){ (*count) = (num - 1); int sieve[num-1], primenums = 0, index,

Implementing the Page Segmented Sieve of Eratosthenes in Javascript

↘锁芯ラ 提交于 2019-11-27 06:29:25
问题 I recently read about a faster implementation of Segmented Sieve of Eratosthenes for really big numbers. Following is an implementation of the same: function sieve(low, high) { var primeArray = [], ll = Math.sqrt(low), output = []; for (var i = 0; i < high; i++) { primeArray[i] = true; } for (var i = 2; i <= ll; i++) { if (primeArray[i]) { for (var j = i * i; j < high; j += i) { primeArray[j] = false; } } } for (var i = 2; i < ll; i++) { if(primeArray[i]) { var segmentStart = Math.floor(low/i