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

Prime Sieve/pairs in a range

I am trying to write a prime sieve generator that I convert to a list for printing and then print the primes in a given range. I'm pretty sure my number of pairs is correct but for some reason I am getting some extra values in my list of primes that…
greenteam
  • 305
  • 5
  • 16
0
votes
1 answer

Will this implementation of a prime sieve work for all primes? or is it just a fluke(Python)

p = 2 for i in range(3,10000000000000000,2): if p%i >= 1: print(i) p = p*(i*i) I've tested it and it seems to work on at least the first 100 primes, will it accurately return primes indefinitely?(theoretically not literally).
MoonMoon
  • 19
  • 5
0
votes
2 answers

Sigsegv Error in finding prime in a range

While solving a question to find prime in a given range ,I am getting a Sigsegv error and I am unable to find where is my mistake and How to correct it #include #include using namespace std; int primes[10000000];// stores prime upto…
Beginner
  • 721
  • 11
  • 27
0
votes
3 answers

prime sieve returning some strange numbers

I'm trying to develop a prime sieve, and on paper my algorithm makes perfect sense on paper, but returns a very short selection of composite numbers among the primes JUST above the square root. For example, with a limit (finding all the primes up to…
Robbie Barrat
  • 510
  • 1
  • 6
  • 24
0
votes
0 answers

Haskell: (Sieve of Eratothenese) Getting the first n primes of the sieve

Let's say I have an expression such as: [2] ++ sieve [3,5..] where sieve (p:xs) = p : sieve [i | i <- xs, i `mod` p /= 0] How would I go about (in a function) taking the first n elements of this list? I'm aware of the take function but I can't…
user3247014
  • 11
  • 1
  • 2
0
votes
2 answers

Failure to understand some prime sieve syntax

Could someone walk me line-by line through this prime sieve? I'm attempting to develop my own sieve but most of the faster ones contain syntax that I don't understand (like the lines i've made comments on). Sorry if this is sort of a newbie question…
Robbie Barrat
  • 510
  • 1
  • 6
  • 24
0
votes
1 answer

haskell sieve prime number

In the following prime sieve: primes :: [Integer] primes = sieve [2..] where sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0] What do x | x <- xs and x `mod` p > 0 mean?
carrotzoe
  • 127
  • 1
  • 1
  • 8
0
votes
2 answers

Sieve of erastothenes primality issue

Set up to print out all false values which are prime numbers however out of 25 it prints. 3, 5, 7, 8, 9, 11, 13, 14, 15, 17, 19, 20, 21, 23, 24, not sure why some of them slip by. Any insight into the matter would be nice. Or simply pointing me in…
asdf
  • 29
  • 4
0
votes
0 answers

Using sieve of sundaram for a given range (b,a)

I used the following code to generate a simple sieve- #include int main() { int a,b,i,j; scanf("%d%d",&a,&b); int m = (a)/2; int d[m+1]; for (i=0;i
Naman Jain
  • 63
  • 1
  • 9
0
votes
2 answers

Paul Erdos Conjecture [Java]

I've been trying to solve this rather easy problem on SPOJ: http://www.spoj.com/problems/HS08PAUL/. It requires the number of prime numbers (less than n) which can be expressed in the form x^2+y^4 (where x and y are integers) to be found out. I've…
AbhyudayaR
  • 51
  • 4
0
votes
2 answers

Finding primes using Sieve of Eratosthenes not working - Haskell

Here is the code I am trying to use: This should generate all primes up to 100 sieve_primes = [x | x<-[2..100], y<-[2..50], z <-[2..25], (x*z) `mod` y /= 0]
0
votes
1 answer

Numbers counting function

I have this assignment in school; we are to write a simple program/method/algorithm in java that has us take two numerical inputs and output count of all the numbers in the range between two inputs which are dividable by 2 or 3 or 5. The assignment…
kamenjan
  • 119
  • 2
  • 11
0
votes
3 answers

How can one verify the proper operation of a sieve close to 2^64?

Small primes - up to about 1,000,000,000,000 - are readily available from various sources. The Prime Pages (utm.edu) have lists for the first 50 million primes, primos.mat.br goes up to 10^12, and programs like the one available at primesieve.org go…
DarthGizka
  • 4,347
  • 1
  • 24
  • 36
0
votes
1 answer

Why doesn't my code generate the prime numbers correctly

The number of prime numbers less than 10,000,000 is 664,579 but my code generates only 664,214. The source of the numbers is https://primes.utm.edu/howmany.html #include #include #include using namespace std; const int…
MNTahhan
  • 23
  • 5
0
votes
1 answer

Java Prime calculator according to Sieve of Eratosthenes

I've stumbled on the following problem: I have a class to get and print all primes between 1 and N. The N is a parameter which you have to insert by yourself. When I insert 10000 for N, the code works and prints out all primes out from 2 to the…