Questions tagged [sieve]

Sieves are a type of algorithm used e.g. in finding primes with the sieve of Eratosthenes, sieve of Atkin etc. "Sieving" refers to gradual dismissal of directly generated sequences of numbers as possible candidates, until only the desired numbers are left.

Sieves are a type of algorithm used e.g. in finding primes with the sieve of Eratosthenes, sieve of Atkin etc., finding lucky numbers, or in integer factorization. "Sieving" the candidate numbers refers to gradual dismissal of directly generated sequences of (in that context, composite) numbers as possible candidates, until only the desired (e.g. prime) numbers are left.

For the unrelated email filtering language, see .

198 questions
1
vote
1 answer

double free or corruption (fasttop): 0x000000000063d070 *** c++ sieve program

I am writing a sieve program in c++. But for every legitimate input, the program always produces output with 4 primes founded and "2 3 5", no matter how the input varies. As I try to run the program via the console, it gives an error message saying…
Echo111
  • 139
  • 2
  • 9
1
vote
1 answer

Totient-function generating sieve consuming too much memory

I have written a sieve-based generator for the list of totients, and want to take the sum up to 1000000. applyEvery :: (a -> a) -> Int -> [a] -> [a] applyEvery f n xs = xf ++ (\(y:ys) -> f y : applyEvery f n ys) xb where (xf, xb) = splitAt (n…
castle-bravo
  • 1,389
  • 15
  • 34
1
vote
1 answer

Prime number algorithm stops working after certain point

Here is my prime number finding algorithm -- it works great (and very fast) up until the limit is set above 173, then it starts throwing ValueError: list.remove(x): x not in list I don't understand why this is when it works absolutely fine up until…
Robbie Barrat
  • 510
  • 1
  • 6
  • 24
1
vote
4 answers

Optimize Speed of Prime Number Sieve (Java)

I'm working on a method in Java which creates boolean array isPrime: boolean[] isPrime; in which prime numbers are labeled with 'true' and the rest with 'false'. While I'm at it I'd also like to count the number of Primes found: int…
Mark
  • 69
  • 1
  • 1
  • 8
1
vote
1 answer

Finding number of divisors of a big integer using prime/quadratic factorization (C#)

I'm trying to get the number of divisors of a 64 bit integer (larger than 32 bit) My first method (for small numbers) was to divide the number until the resulting number was 1, count the number of matching primes and use the formula (1 + P1)(1+…
Bartemis
  • 13
  • 3
1
vote
1 answer

Chain of Sieves to generate prime numbers C++

I'm trying to feed each prime number found into a chain of "sieve" objects. The below code achieves what I eventually want to do, but each sieve (Prime number)class is manually implemented (to check subsequent numbers are divisible by the stored…
Jerry
  • 424
  • 1
  • 4
  • 17
1
vote
2 answers

Adding elements to an array - Pascal

program Primes(input,output); var candidates, primes : Array[0..999] of Integer; n, i, j : Integer; begin for i := 0 to 999 do begin candidates[i] := 1; end; candidates[0] := 0; candidates[1] := 0; i := 0; while i < 1000 do …
Kate
  • 45
  • 4
  • 8
1
vote
2 answers

Improving performance on Sieve method

I am writing a method to find primes up to n(Sieve of Eratosthenes), yes this is for homework. I am looking to improve performance in the method I have written. I have been tweaking this for the last few days but am unable to to follow the…
D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
1
vote
2 answers

What are the advantages of checking if N is a prime number using square root of N versus N/2?

Is it a matter of cutting out iterations to check if a number is a prime? ex. 37 is a prime, and checking up to 18.5 (half of 37) versus 6.08(square root) cuts out a lot of the work, but both follow the same principle? sorry for asking, i am trying…
1
vote
1 answer

Zebra striping - Tablesorter vs Sieve

I have some tables which use the jQuery plugin 'tablesorter' to allow easy sorting. Recently, I found out that it included a zebra striping widget. I enabled it, and it's been working well. I also decided to add the 'Sieve' plugin, as an…
Damien H
  • 174
  • 11
1
vote
3 answers

What is the space complexity of a prime sieve with data in proportion to number of primes?

I'm practicing writing algorithms optimized for space or time complexity. With prime sieves, at minimum you must store a list of all primes found. It seems data in proportion to the number of primes found is the least amount of space such an…
1
vote
1 answer

Excluding Numbers for Sieve of Sundaram

I'm working on implementing the Sieve of Sundaram. The first step is to get a list of Integer's such that: i, j are Natural Numbers, 1 <= i <= j i + j + 2*i*j <= n Here's my function. It's supposed to generate a list of tuples of all (i, j)'s…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
2 answers

How the channels work in this example?

This is is an example of prime number sieve package main func Generate(ch chan<- int) { for i := 2; ; i++ { ch <- i } } func Filter(in <-chan int, out chan<- int, prime int) { for { i := <-in if i%prime != 0 { out <- i …
John
  • 3,821
  • 2
  • 18
  • 25
1
vote
9 answers

Finding composite numbers

I have a range of random numbers. The range is actually determined by the user but it will be up to 1000 integers. They are placed in this: vector n and the values are inserted like this: srand(1); for (i = 0; i < n; i++) v[i] = rand() %…
Doug
  • 1,316
  • 6
  • 19
  • 36
1
vote
2 answers

Quadratic Sieve - What does o(1) stand for?

I'm trying to implement the Quadratic Sieve, and i noticed i need to choose a smoothness bound B to use this algorithm. I found in the web that B also stands for exp((1/2 + o(1))(log n log log n)^(1/2)) but now my problem is o(1). Could you tell me…
Michael
  • 1,018
  • 4
  • 14
  • 30