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

No Output for Prime Sieve

I'm trying to print out a particular set of primes using a sieve, but I just don't seem to get any output yet it all compiles fine. The program doesnt exit unless I force it, so I'm guessing its stuck somewhere...How can I fix this? #include…
1
vote
1 answer

Getting WA in ANUGCD from Codechef March Long Contest

I am Getting WA in the Question GCD Condition from Codechef March Long Contest. Kindly tell me what I've done wrong or some test case where the code produces Wrong answer. Link for the Question I Have used RMQ(Range maximum Query) for every prime…
Dhruv Chandhok
  • 780
  • 7
  • 18
1
vote
2 answers

How do I define the sieve function for prime computation using higher–order functions?

I have a recursive definition of sieve in Haskell for prime number computation. But I don’t know how to write the same function using higher–order functions such as map or filter. Can anybody show me please? sieve [] = [] sieve (x:xs) = check…
rips
  • 39
  • 2
  • 6
1
vote
2 answers

Java data-type issue

I have written a function to work on prime numbers using the sieve of Eratosthenes method. The function works fine using integers but I am now trying to implement support for long so that I can work with large numbers. I cannot seem to get the…
Wesk
  • 115
  • 1
  • 1
  • 6
1
vote
1 answer

about Sieve of Eratosthenes

I've got some trouble with the sieve of eratosthenes. So i've got the mathmatics calculations for the sieve from a book called "Schaum's outlines" but i think the book has programmed to code wrong... This is the code from the book: public class…
SteelDevil
  • 29
  • 8
1
vote
2 answers

How to improve memory intensive Python scripts?

Today, I wrote a short script for a prime sieve, and I am looking to improve on it. I am rather new to python and programming in general, and so I am wondering: what is a good way to reduce memory usage in a program where large lists of numbers are…
Plopperzz
  • 334
  • 2
  • 15
1
vote
2 answers

Python sieve prime numbers

I am trying to get the sum of all prime numbers using a sieve on Python 2.7. However when I run the program I only wind up with 0 everytime. I have no idea why this is happening. import math,time start=time.clock() def primesieve(limit): …
1
vote
6 answers

Sieve of Erastothenes

I'm trying to figure out how to use the sieve of eratosthenes to find the prime numbers from 1-300. I'm having trouble figuring it out, so any help would be nice! Btw, im new to programming so if you could keep it simple that would be best Below is…
1
vote
1 answer

Is this an optimal prime generator?

Is this in any way an optimal solution for finding primes? I am not trying to add every optimization under the sun, but is the principal good? def primesUpto(self, x): primes = [2] sieve = [2] i = 3 while i <= x: composite =…
1
vote
3 answers

Finding a Prime Sieve Inconsistency in Python

I'm attempting to learn python and I thought trying to develop my own prime sieve would be an interesting problem for the afternoon. When required thus far, I would just import a version of the Sieve of Eratosthenes that I found online -- it's this…
MDd
  • 35
  • 1
  • 1
  • 8
1
vote
3 answers

faster Sieve of Erathostenes and prime number factorization in Java

My input is an Integer. Up to that value, all prime numbers should be found and printed in 5 columns, then I have to "prime factorize" the integer and print the result. It wokrs fine, but it'ts too slow... public class Bsp07 { public static void…
Flo
  • 33
  • 1
  • 5
0
votes
0 answers

Error creating spam filter rules in email body in dovecot

I have been applying the following rule to mark as spam if the body contains any reference or coincidence with the following "earn free money": `#if body :contains "earn free money" { # fileinto "Junk"; # stop; #} #if anyof ( # header :matches…
Otto
  • 101
0
votes
0 answers

Parallel SieveOfEratosthenes

I am trying to parelleize Sieve Of Eratosthenes, the idea to do this is this: First find the primes to square root of N. these primes will be evenly distributed to the number of threads. These threas will now for each prime they have cross multiples…
feter
  • 23
  • 5
0
votes
2 answers

how do i make a array with lots of places in c?

I'm making the sieve of erasthostenes in c. I have programmed it in other languages before but I never encountered this problem. Here's my algorithm: #include #include #include #include #include
0
votes
1 answer

Postfix+Dovecot How do I BCC an email back to the sender?

The end result I'm trying to achieve is that emails sent out should go into the sent box as well. I've tried multiple ways to do this, inspired by various other answers, but none have worked so far. I'm able to send and receive emails, but they…
Axle12693
  • 46
  • 6