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

Formula for reliably (over-)estimating the number of primes in interval [m, n]?

For quite a while now I've successfully used a simple function that reliably (over-)estimates the number of primes up to a given n, for example for allocating space to hold the primes. Now I'm looking for something that does the same for the number…
DarthGizka
  • 4,347
  • 1
  • 24
  • 36
1
vote
0 answers

Need a mandatory condition in subject before testing regex in body

I am a new dev in SIEVE and I am trying to create a filter in Thunderbird with two conditions. sorry if the question is dumb first: Subject must match a specific string ([SUPPORT]) second : if some terms are present flagged the email in…
kalimbra
  • 11
  • 1
1
vote
2 answers

Recursive Sieve of Erasthotenes returning None

I implemented a recursive Sieve of Erasthotenes, which, from the debug statements used, appears to work, but returns None. The code with the debug statements looks like this: def sieb2 (iterable, container): print("Just called:", iterable,…
E. Staikov
  • 106
  • 8
1
vote
0 answers

Sieve filter not running

I am trying to automatically move mails detected as spam to the junk folder but my sieve filters are not running. I can send and receive mails and mails are detected as spam. X-Virus-Scanned: amavisd-new at ... X-Spam-Flag: YES X-Spam-Score:…
1
vote
0 answers

Problem implementing wheels to sieve of Eratosthenes

I am a bit struggling with further optimizing my prime calculating function. So far I ended up with the sieve of Eratosthenes. I found on https://primesieve.org/ a hint to further optimize this with the implementation of wheels and a link to this…
1
vote
1 answer

How to solve this Racket problem using higher order functions?

I am stuck on Q2. Q1. Write a function drop-divisible that takes a number and a list of numbers, and returns a new list containing only those numbers not "non-trivially divisible" by the the number. This is my answer to Q1. (define (drop-divisible…
Zoe Sun
  • 89
  • 1
  • 2
  • 7
1
vote
2 answers

My Java Sieve code is slow and not scaling at the expected time complexity

I have wrote the following 'segmented sieve' program in Java. It take a range of numbers to sieve, crosses out composite numbers using the 'sieving primes' (primes arraylist variable) then returns the prime numbers that have not been crossed out.…
1
vote
1 answer

Concurrent Sieve in Erlang

I have a code that uses the Sieve of Eratosthenes method to generate prime numbers up to a given limit N. Method: Split the list of odd numbers into segments Each segment gets passed to a process Segments are sieved concurrently with the set Lp…
1
vote
1 answer

python: multiplication in for loop skipped on second iteration

I am trying to implement the Sieve of Euler (as described on programmingpraxis.com).I have code that runs fine on the first iteration, however on the next iteration my multiplication is skipped for some reason that escapes me (probably just missing…
Andreas_B
  • 113
  • 5
1
vote
1 answer

Counting primes up to 18 digits optimization

I have a task at school to count number of primes up to 10^18 in under 2 minutes and with no more than 2 GB of memory to use. For the first try I've implemented a segmented sieve with the following optimizations: used 32 bit integers to store the…
Marcus
  • 128
  • 2
  • 12
1
vote
1 answer

Is this sieve really O(n)?

Can anyone please tell me how this is working in O(n). http://www.geeksforgeeks.org/sieve-eratosthenes-0n-time-complexity/ void manipulated_seive(int N) { // 0 and 1 are not prime isprime[0] = isprime[1] = false ; // Fill rest of the…
rittik
  • 63
  • 5
1
vote
0 answers

SPOJ - NDIV Cant find the error

I have implemented sieve approach and it runs correctly for my test cases. I used a counter rather than a flag for all numbers and the times the numbers been accessed. When i run it on SPOJ it gives wrong answer. Here is the…
Parth Mahajan
  • 119
  • 1
  • 4
1
vote
3 answers

Fast Prime Generator besides Sieve

I recently made this bit of code, but wonder if there is a faster way to find primes (not the Sieve; I'm still trying to make that). Any advice? I'm using Python and I'm rather new to it. def isPrime(input): current = 0 while current <…
Emil
  • 41
  • 2
  • 10
1
vote
2 answers

Why is my Seive of Eratosthenes Algorithm implementation running into infinite loop?

I was implementing Sieve's Algorithm for finding Prime Numbers up to n. I am unable to find out why is it running into infinite loop. Here I'm giving the code snippet. Please help. for(int j=2;j<=Math.sqrt(n);j++){ if(a[j]==true){ int x=0; …
tourist
  • 506
  • 1
  • 6
  • 20
1
vote
3 answers

Sieve of Eratosthenes Optimization

I've made my own program that finds primes from 2 - n, using the Sieve of Eratosthenes. Is there any way I can implement a more efficient way to remove composite numbers? Link to project: https://github.com/Gurran/Sieve-of-Eratosthenes class…
Gustav Blomqvist
  • 161
  • 1
  • 12