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
2
votes
3 answers

Gdal sieve filter in python

I want to sieve a classified image in py, and I try to use the gdal sieve function, but it will not work: Syntax: SieveFilter(Band srcBand, Band maskBand, Band dstBand, int threshold, int connectedness=4, char ** options=None, GDALProgressFunc …
svein
  • 21
  • 1
  • 2
2
votes
1 answer

Sieve of Eratosthenes Understanding

I have this code I do not quite understand because I just started learning Python a week ago. import numpy as np import time start_time=time.clock() def Sieb(n): #Sieve Eins = np.ones(n, dtype=bool) #Eins is just…
Lennox
  • 45
  • 4
2
votes
0 answers

Index out of bounds when adding to ArrayList

Edit: Just to point out, I know what index out of bounds usually means - I would not make this post if it wasn't something I've never encountered before, which in this case is an array list that refuses to add a plain old int of 6000 or so, and a…
Telanore
  • 75
  • 1
  • 9
2
votes
2 answers

Most effecient algorithm for finding this LCM summation

Problem : Find Range of n : 1<= n <= The main challenge is handling queries(Q) which can be large . 1 <= Q <= Methods I have used so far : Brute Force while(Q--) { int N; cin>>N; for(int i=1;i<=N;i++) ans += lcm(i,N)/i…
Sarvagya
  • 89
  • 8
2
votes
2 answers

Sieve gets stuck at the beginning

I wrote the following sieve: isPrime :: Integer -> [Integer] -> Bool isPrime n = all (\i -> n `mod` i /= 0) sieve :: [Integer] sieve = 2 : [i | i <- [3,5..], isPrime i sieve] but I don't understand why it gets stuck after the first value. Running…
rubik
  • 8,814
  • 9
  • 58
  • 88
2
votes
1 answer

Looking at a prime sieve program but unsure why it keeps coming up with an error about slice length

def primes(n): sieve = [True] * n for i in xrange(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False] print [2] + [i for i in xrange(3,n,2) if sieve[i]] primes(int(raw_input("Please enter an upper limit…
Aaron
  • 155
  • 3
  • 11
2
votes
4 answers

Sieve of Eratosthenes - Implementation returning some non-prime values?

I implemented the Sieve of Eratosthenes in Java, from pseudocode: public static void sieveofEratosthenes(int n) { boolean numArray[]; numArray = new boolean[n]; for(int i = 0; i < n; i++) numArray[i] = true; int a = 0; …
Tetramputechture
  • 2,911
  • 2
  • 33
  • 48
2
votes
3 answers

Good design pattern for running a process on a collection of data?

Best explained with code I think, this is just a simple example: public class MyPOJO { public String name; public int age; public MyPOJO(String name, int age) { this.name = name; this.age = age; } } public class…
DanInDC
  • 5,019
  • 8
  • 31
  • 25
2
votes
3 answers

Python Sieve of Eratosthenes not working

First of all, this is HOMEWORK, I am currently working on a Sieve of Eratosthenes on python. My program looks like: x=[] for i in range(2,100): x.append(i) primes=[] i=2 while len(x)!=0: k=x[0] x.pop(0) primes.append(k) …
Eed
  • 385
  • 1
  • 2
  • 7
2
votes
1 answer

How to divisor sieve numbers of form kn^p?

Creating a divisor-counting sieve for all numbers 1-n is well known func sieve(n) counts = array of size n+1, all elements set to 1, counts[0] = 0 arbitrary for 2 <= i <= n for i <= j <= n, stepwise i counts[j]++; …
RTG_FRE
  • 87
  • 1
  • 7
2
votes
4 answers

Python: How to slice a list to a certain value

I was wondering if there is way to slice an existing list to a certain number that is most likely not in the list. For example, suppose I have: primes = [2,3,5,7] Now I want to test the number 11 for primness. I will do so by trial division by all…
Amit Shah
  • 43
  • 4
2
votes
1 answer

efficient sieve of Euler in stream processing style

Sieve of euler has a better asymptotic complexity than Sieve of Eratosthenes, and can be implemented simply in Imperative languages. I'm wondering wether there is any way to implement it elegantly with streams .I've checked the haskell wiki about…
FooBee
  • 778
  • 7
  • 23
2
votes
1 answer

Quadratic sieve and nth powers

I implemented the quadratic sieve in Haskell according to the basic algorithm specified on the Wikipedia page. It works great on most integers, however it fails to find a factorization on numbers N that are nth powers. For even powers (squares), the…
Nick
  • 2,821
  • 5
  • 30
  • 35
2
votes
4 answers

SPOJ PRIME1 : TLE

I tried implementing the segmented sieve algorithm for this [question]:http://www.spoj.pl/problems/PRIME1/ as follows : #include #include #include…
spd
  • 103
  • 1
  • 7
1
vote
1 answer

What configuration is needed to remove attachments from mails in Dovecot Sieve?

How can I remove specific attachments from mails in dovecot sieve mail server ? I have tried several configurations but the attachments were not removed. But it did not know keyword "replace" and I don't know what it requires. I am using…
Janumar
  • 202
  • 2
  • 7