192 questions
1
vote
1
answer
227
views
Optimizing sieving code in the Self Initializing Quadratic Sieve for PyPy
I've coded up the Self Initializing Quadratic Sieve (SIQS) in Python, but it has been coded with respect to being as fast as possible in PyPy(not native Python).
Here is the complete code:
import ...
1
vote
0
answers
154
views
Sieve filtering - "body" extension not working as expected
I am attempting to write a Sieve email filter using the "body", "regex", and "variables" extensions.
Following is a very simplified version of the filter to test/...
3
votes
1
answer
129
views
Why this idea to generate the primes in Haskell doesn't seem to work?
I'm trying to use the Sieve of Eratosthenes' algorithm in Haskell to generate a stream of primes but the code doesn't seems to work. This is the main idea.
The main idea is derived from our functional ...
2
votes
1
answer
298
views
making a sieve for an expensive for loop
I'm trying to write code that is done over a lot of values, and my code is doing a ton of extra work. I'm not even quite sure mathematically how to describe the values I want to skip, because as i ...
0
votes
2
answers
117
views
how do i make a array with lots of places in c?
I'm making the sieve of erasthostenes in c. I have programmed it in other languages before but I never encountered this problem. Here's my algorithm:
#include <stdio.h>
#include <stdbool.h>...
1
vote
1
answer
225
views
Choosing the size of the segment in segmented sieve of Eratosthenes
I made this segmented sieve that uses wheel factorization.
Here you find the explanation.
By setting the wheel size to 210 and using a segment vector uint8_t of size 277140 = 6 * (11 * 13 * 17 * 19 + ...
-1
votes
1
answer
94
views
How is this Eratosthenes Sieve implementation is working internally?
I found this code that seems to be the non-optimal version of the Sieve of Erastothenes, it gets the N first prime numbers into an array.
private IntPredicate p = x -> true;
private int[] primes(...
1
vote
1
answer
207
views
Improving SICP primes sieve's time complexity
A recent Q&A entry showcased the following primes generating code from SICP, using lazy streams:
(define (sieve stream)
(cons-stream
(stream-car stream)
(sieve (stream-filter
(...
0
votes
0
answers
125
views
Double Segmented Primes Sieve
In cases of low memory available I thought it was possible to implement a double-segment sieve to find prime numbers in a neighborhood of n. In practice, a segmented sieve has dimension dim_seg_1 for ...
3
votes
1
answer
227
views
How to look for factorization of one integer in linear sieve algorithm without divisions?
I learned an algorithm called "linear sieve" https://cp-algorithms.com/algebra/prime-sieve-linear.html that is able to get all primes numbers smaller than N in linear time.
This algorithm ...
4
votes
2
answers
564
views
Postponed Sieve algorithm with start logic
Based on this Python answer by Will Ness, I've been using a JavaScript adaptation for the postponed sieve algorithm from that answer:
function * primes() {
yield 2;
yield 3;
yield 5;
...
1
vote
0
answers
307
views
If the time complexity of Sieve of Atkins is better than Sieve of Eratosthenes, why does Eratosthenes always have a quicker runtime
I'm doing a project on Sieve of Atkins and I was exploring why this algorithm was created. From what I understood was that it was a way of finding prime numbers and it ran faster than Sieve of ...
1
vote
2
answers
526
views
Modified Sieve for finding Prime Numbers in Scheme
I am working on coming up with a solution for coming with a list of prime numbers using the Sieve of Eratosthenes. So the program is supposed to find prime numbers up to a specific number "n"...
1
vote
1
answer
367
views
Time complexity of sieve algorithm
Unlike the traditional sieve of Eratosthenes:
n=10000000
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
sieve=[2] + [i for ...
-2
votes
1
answer
140
views
Understanding the sieve of Eratosthenes [closed]
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 ...
4
votes
0
answers
178
views
Sieve of Euler space complexity in Haskell
I was given 2 different algorithms written in Haskell aimed to generate the first k primes. As the title suggests, they are the Sieve of Eratoshenes and Euler.
I am trying to understand why Euler ...
5
votes
5
answers
2k
views
Making Sieve of Eratosthenes more memory efficient in python?
Sieve of Eratosthenes memory constraint issue
Im currently trying to implement a version of the sieve of eratosthenes for a Kattis problem, however, I am running into some memory constraints that my ...
0
votes
0
answers
20
views
What will be the complexity if we want to calculate no. of digits between 1 to 10^12 whose no. of factors are exactly 4?
like for 1 to 10
no of such digits are 3.Because only 6,8 and 10 have no. of factor 4 (including 1 and the number).
We can not use SIEVE because we can not construct an array of Length 10^12.
Share ...
4
votes
3
answers
148
views
Why are these sieve optimizations breaking my code?
And how can I correct them to work?
I am trying to optimize my sieve per previous suggestions, but in both instances the code breaks:
Incrementing j = j + ( i * 2) will break the code.
Obviously I'm ...
1
vote
0
answers
109
views
Index out of range error sieving B-smooth numbers with logarithms
So I have been trying to implement the quadratic sieve and I did step 1 which is(in code):
f = 44
b = ceil(sqrt(n))
factorBase = [i for i in genPrimes(f) if jacobi(n, i) == 1]
t = [modInverse(n, p) ...
3
votes
1
answer
1k
views
Parallelizing Sieve of Eratosthenes in Java
I am trying to make a parallel implementation of the Sieve of Eratosthenes. I made a boolean list which gets filled up with true's for the given size. Whenever a prime is found, all multiples of that ...
0
votes
0
answers
362
views
Find a pair of co-prime numbers
We are given an array.
array size <= 1e4.
1 <= A[i] <= 1e18.
We can run a double loop to find gcd of each possible pair. Is there any optimized algorithm?
0
votes
0
answers
52
views
Wrong answer on SPOJ (PRIME1)
Here is the link to the problem -> PRIME1
It asks us to print all the prime numbers between two numbers m and n
I used segmented sieve to solve the problem. Stored all the primes till sqrt(10^9) and ...
1
vote
2
answers
50
views
Recursive Sieve of Erasthotenes returning None [duplicate]
I implemented a recursive Sieve of Erasthotenes, which, from the debug statements used, appears to work, but returns None.
The code with the debug statements looks like this:
def sieb2 (iterable, ...
-3
votes
1
answer
53
views
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 <vector>
#...