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

C++ How to use functions from a cpp file in a header file

I have a class in a header file called bitarray.h and a corresponding bitarray.cpp and I also have a sieve.h. The sieve.h and bitarray.cpp #includes the bitarray.h and sieve.h only has a function void Sieve(BitArray a). I would like to call Set()…
0
votes
2 answers

Segmentation fault with a Sieve of Eratosthenes program

I'm trying to implement the sieve algorithm where it'll ask for the size of a list of consecutive numbers and print out the prime numbers in that list, but I'm getting a seg fault: 11 error. This is my code: #include #include…
user3291818
  • 203
  • 1
  • 3
  • 11
0
votes
2 answers

Generating array of array of divisors in python

I wish to get divisors of number n as a list stored in a master list at nth position. For example the sieve of length 11, I want sieve[6] == [2,3,6] (ignoring 1). My code below does not work and surprises me in an unpleasant way: sieve =…
user2685079
  • 104
  • 9
0
votes
2 answers

Sieve Of Atkin is surprisingly slow

I recently became very interested in prime numbers and tried making programs to calculate them. I was able to make a sieve of Sundaram program that was able to calculate a million prime numbers in a couple seconds. I believe that's pretty fast, but…
0
votes
1 answer

Getting result 1 less or 1 more, divisor counting Program - C

I'm solving a problem. Problem Link: http://www.codechef.com/NOV13/problems/PRETNUM The Problem is about counting the numbers having their divisor count prime (numbers having their number of divisors prime) in the given range of L and R.…
abhishekkannojia
  • 2,796
  • 23
  • 32
0
votes
1 answer

Reasons of the execution time spikes during N runs of Sieve of Eratosthenes algorithm

I developed the Sieve of Eratosthenes algorithm in Java and I wanted to measure its performance. Basically I run the "core algorithm" (not the entire application) 5000 times (with a for loop) and measure its execution time. Here it is the code I…
HBv6
  • 3,487
  • 4
  • 30
  • 43
0
votes
3 answers

Java Eratostenes sieve,printing only the biggest prime from a given ceiling?

everyone!I have a java app that shows all the prime numbers from 2 to a given number(user input).How can I print out just the last number, the biggest one I mean, from the given range? For example:if the user input is 12,the compiler prints only…
0
votes
2 answers

Sieve of Eratosthenes C++

currently I'm working on a project, where I want to calculate all prime numbers. When I compile (MINGW Windows Comp.) the programm crashes and returns a random error number. This is the Code I've written: http://pastebin.com/4vVnAM2v /* Sieb des…
benni
  • 37
  • 8
0
votes
2 answers

Increasing a for loop integer j by i in Java

I want to turn this "pseudocode" into something that works in Java and I'm having trouble for j = i², i²+i, i²+2i, ..., not exceeding n: Would this be correct? for (int j = i*i; j < n; j++) { //other code here that does the operation: …
isaacn18
  • 1
  • 2
0
votes
1 answer

Improving efficiency of my Sieve of Eratosthenes in Ruby?

Below is my implementation of the Sieve of Eratosthenes to find prime numbers up to the upper limit parameter. Currently, my code completes in around 2 seconds when my parameter is 2,000,000. I see that I'm making one extra step by setting the…
jchi2241
  • 2,032
  • 1
  • 25
  • 49
0
votes
2 answers

Issue with longs dividing and then modding correctly in Python

I'm trying to implement a primality test for an RSA implementation I'm writing as an excercise. I'm mainly using Rabin-Miller, but I do have a Sieve of Eratosthenes formulating a list of all the primes under a thousand to use for a quick test to…
0
votes
2 answers

Weird Output with first case integer

Here are two functions below that compile perfectly but I seem to be getting a weird error with the very first inputted integer. I have tried debugging in GDB but when it's only the first inputted value that is having this weird error, then it makes…
0
votes
3 answers

Not Finding Times of Prime Generation / Limited Generation

This program is a c++ program that finds primes using the sieve of eratosthenes to calculate primes. It is then supposed to store the time it takes to do this, and reperform the calculation 100 times, storing the times each time. There are two…
Nathan J
  • 195
  • 10
0
votes
1 answer

"application: not a procedure" while generating prime numbers

I am trying to output the first 100 prime numbers and keep getting the error: application: not a procedure; expected a procedure that can be applied to arguments given: (#) arguments...: [none] The error is shown in my take$ procedure here: (if…
0
votes
4 answers

My implementation of the Sieve of Eratosthenes is flawed?

I am making a Sieve of Eratosthenes implementation in Python. A problem that occurs is not all primes appear (mainly the lower numbered ones). Here is my code: def prevPrimes(n): from math import sqrt from time import time start =…
Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94