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
0
votes
0 answers

Why is this Prime Sieve only working up to a bit less than Integer.MAX_VALUE?

I found this code here on StackOverflow: public static BitSet computePrimes(int limit) { final BitSet primes = new BitSet(); primes.set(0, false); primes.set(1, false); primes.set(2, limit, true); for (int i = 0; i * i < limit;…
phil330d
  • 31
  • 1
  • 4
0
votes
1 answer

Eliminate large clumps with gdal_sieve?

I have a raster dataset and have used gdal_sieve to eliminate clumps of pixels made up of below a certain number of pixels. How do I eliminate large clumps of pixels above a certain number of pixels?
Blazinator
  • 125
  • 4
0
votes
1 answer

Sieve of Eratosthenes without multiples of 2 and 3

I am trying to implement the algorithm described in this article Faster Sieve of Eratosthenes. I quite understand the idea but I cannot grasp how exactly could it be implemented via python code. After some work I found a way to convert indexes from…
Eric Rovell
  • 393
  • 1
  • 6
  • 15
0
votes
0 answers

Runtime for Sieve of Eratosthenes

I am currently working on making a sieve for school. Here is my code so far: public static List sieve(int input) { int[] numbers = new int[input - 2 + 1]; int prime = 2; // start of with 2 since first prime w/ specific…
Henry Wang
  • 161
  • 2
  • 2
  • 14
0
votes
2 answers

how to use for loop to calculate a prime number

for i in range(2, 101): for j in range(2, i): if (i % j) == 0: print(i,"is a composite number") break I tried making the if (i%j) != 0: but then it wouldn't work (4 is not a prime number)
Haoyang Song
  • 162
  • 12
0
votes
0 answers

CPP Prime Generator SPOJ Sieve

I did implement Sieve prime generator. The code is pretty fast and consumes less memory. https://www.spoj.com/problems/PRIME1/ But I get "Wrong Answer" when I submit the solution. People online seem to just make the set the max to 32000 and run the…
Gnanesh
  • 668
  • 7
  • 13
0
votes
0 answers

How can I optimize the speed of this Mersenne Prime Sieve in Python?

I need help regarding a Mersenne Prime Sieve which I edited to perform this task; this code is from a perfect number generator. The problem is the program slows down at 11213 in python. Can anyone offer some speed enhancements for this sieve? The…
Tom E. O'Neil
  • 527
  • 4
  • 10
0
votes
2 answers

Sieve of Eratosthenes for higher numbers than 2 Million [C]

I am trying to make a program which names all prime numbers up to n. When I enter numbers > 2 Million, the program crashes. Can someone help me? #include #include void sieve(unsigned long long int n, char primes[]); int…
Nord
  • 7
  • 2
0
votes
2 answers

sieve of eratostheness algorithm

I have this function for calculate prime numbers with sieve of eratosthenes. I have one error i don't understand why. def era1(n): llista1 = [] llista2 = [] i = 2 while(i<(n+1)): llista1.append(i) i = i + 1 …
user7734947
0
votes
1 answer

Have i made a new prime finding algorithm, and are there faster ones? (Python)

Lately I have done some reading about primes, and decided to make my own program for finding them (not for school or anything, just hobby). this is the code: import time a=[2,3] e=[0,1,1,1,0,1] b=0 c=0 d=[] length=int(input("primes til…
tjjensma
  • 9
  • 2
0
votes
0 answers

Converting void to int C++

Writing a program using the Sieve of Tratosthenes theory and I cant covert void to int. Heres my code: #include #include #define limit 1000000 /*size of integers array*/ void *malloc(size_t size) int main(){ unsigned long…
dreed
  • 11
  • 3
0
votes
3 answers

Error on finding larger primes

I made a simple sieve of erastothenes program to calculate the sum of primes up to n for project euler. It works fine for 100, 1,000 , 10,000 and so on but when i do 1 or 2 million, it gives me this…
udbhavs
  • 98
  • 10
0
votes
1 answer

Find total number of Equal Partition

For a number N f(N) = the total number of parts in the partitions of N into equal parts. For example if the given number is 4, the equal partitions will be: {1,1,1,1} ->total parts=4 {2,2} -> total parts=2 {4} -> total…
msank
  • 21
  • 1
  • 4
0
votes
1 answer

How do I call a list or object defined in another instance into another instance?

class Sieve: def __init__(self, digit): self.digit = [] numbers = [True]*digit if digit <= -1: raise RuntimeError("Cannot use negative values.") numbers[0] = False numbers[1] = False def findPrimes(self): for i in…
0
votes
1 answer

Accessing an array at a variable index

I am brand new to MIPS and am attempting to write the Sieve of Eratosthenes algorithm as described on Wikipedia to find all prime numbers from 1 to 1000. I am just following the steps outlined in 1-4, and not yet any of the refinements…
KOB
  • 4,084
  • 9
  • 44
  • 88