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
1 answer

Almost Finished! C++ Prime Number Sieve over Sockets

I have poured over my code for the past 5 hours and have gotten nowhere. Whenever I run my code, I get a Segmentation Fault. Sometimes it happens on the client side, sometimes on the server side, so I'm just not sure what's happening. The code…
Rick_Sch
  • 456
  • 3
  • 10
  • 19
0
votes
2 answers

integer division vs regular division

I need to compare an integer in a loop to the quotient of a long and a long. in order to not do integer division, if I understand correctly do I need to convert one of the longs into a double? long prime = primes[d]; int i = 1; // "inputNumber /…
stackOverFlew
  • 1,479
  • 2
  • 31
  • 58
-1
votes
2 answers

Sieve of Eratosthenes (USING LINKEDLIST)

Im trying to figure out how i would manipulate Lists in order to find all the primes up to a number provided by the user, i have a list steps which im trying to follow which are create and fill list of possible primes Basically an arrayList that…
MaroTS
  • 35
  • 9
-1
votes
3 answers

Prime Sieve algorithm in Python : Help Explaining

I came across this prime sieve using the enumerate function which I vaguely understand, I understand the general idea behind the code, i.e. turning all the non-prime values in the list of 'True' to 'False' and then out of that creating a prime list.…
Anonymous
  • 13
  • 1
-1
votes
1 answer

C code for Sieve of Erastothenes

Can someone please tell me why my programme is outputting all primes up to inputted n and also just the number n+2 (whether it is prime or not)? And also sometimes n+1 if it is prime, e.g. for inputting n=10, output is 2,3,5,7,11,12. Here is my…
-1
votes
1 answer

Creating SIEVE with vectors

I'm trying to make a simple sieve with vectors : #include #include #include using namespace std; vector myVector; void vec_sieve() { myVector.push_back(0); myVector.push_back(0); unsigned int sz =…
inhaler
  • 175
  • 1
  • 2
  • 12
-1
votes
1 answer

value requires 1000000000 bytes, which is more than max-value-size

I am stuck with this problem on spoj.com http://www.spoj.com/problems/PRIME1/ After reading a bit about prime generation algorithms, I found that "Sieve of Atkins" is the fastest prime generation algorithm. I have partially implemented the algorithm…
Lakshmikant Deshpande
  • 826
  • 1
  • 12
  • 30
-2
votes
1 answer

Understanding the sieve of Eratosthenes

I am currently going through all of the algorithms we learned about in a certain class, trying to understand what each does and how. However, I am a bit clueless about a certain line in our Eratosthenes sieve: def sieve(n): primes = [] …
CodeAche
  • 13
  • 3
-2
votes
1 answer

How do I increase the size of an array to fit all prime numbers in increment of 100 starting from 1 (1, 101, 201, 301.. and so on)?

#include using namespace std; void SieveOfEratosthenes(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { …
AB3
  • 67
  • 6
-2
votes
1 answer

Finding pairs such that product is equal to the elemnts of third aaray in less than o(n^2)

Given three sorted arrays say A,B and C. The range of values of A and B are <10^5,while for C the range is upto 10^10 but all C elements are perfect squares.. Count all the pairs of A and B such that there product is equal to any element of C. I…
Coder doit
  • 25
  • 5
-2
votes
2 answers

need help about sieve of eratosthenes in free pascal

my teacher gave me this : n<=10^6; an array of n integer :ai..an(ai<=10^9); find all prime numbers . he said something about sieve of eratosthenes,and I read about it,also the wheel factorization too,but I still couldn't figure it out how to get the…
-2
votes
1 answer

Sieve of Eratosthenes in AT&T Assemby

I have written a simple program in C to find all prime numbers within a given range using Sieve of Eratosthenes. In school, we are currently learning assembly in a class, but I can't figure out how to write the three loops. I have somewhat figured…
erikst
  • 23
  • 5
-2
votes
1 answer

My sieve of eratosthenes implementation in Python

Could you please take a look at my implementation of the sieve of eratosthenes in Python and tell me how can I improve/optimize it? I'm a beginner in programming, so I don't have any ideas how to optimize it, and I'd really appreciate it if you…
-3
votes
1 answer

Bad Access on Sieve

My block of code runs, but whenever I type in input, it returns Thread 1: EXC_BAD_ACCESS (code=1, address=0x4). I'm fairly new to coding, and was wondering what's wrong. #include #include #include using namespace…
-3
votes
1 answer

Implementing Sieve of Eratosthenes in Delphi 5

I need to programm the Sieve of Eratosthenes in Delphi 5 as a school homework project. This is what i currently have: There is one problem: At the end of the last for-"loop" it says"if zahl[i] then write(i:8);". I suppose it should give out the…
Keyinator
  • 111
  • 2
  • 10
1 2 3
13
14