Questions tagged [primes]
Primes or prime numbers are numbers which are divisible only by themselves and one, starting with 2, 3, 5, 7, 11.... They are commonly used in encryption and hashing algorithms.
722 questions
9
votes
4
answers
809
views
Find the smallest semiprime satisfying a bunch of conditions
The purpose of this code is to find the smallest semiprime \$s = a b\$ satisfying a bunch of conditions stated in the Math.SE question What is the smallest "prime" semiprime?. The conditions ...
3
votes
1
answer
178
views
Java: counting letters FROM A fractal algorithm shows prime number patterning
This example finds all "letter" structures.
letter a = LMLMMM
letter b = LMMMMM
letter c = MMLMMM
letter d = MMMMMM
Symbol L = live = prime candidate number
Symbol M = multiple = composite ...
5
votes
1
answer
472
views
Java: prime number envelopes FROM A fractal algorithm shows prime number patterning
It implements prime number envelopes (page 3) from my paper: https://zenodo.org/records/16829092
The full working example is on github: https://github.com/cerebrummi/primeenvelopes
"StartFA"...
10
votes
2
answers
1k
views
Java: A fractal algorithm shows prime number patterning
The fully working example finds all primes (theoretically). In real life the FA is constrained by stack size. The theoretical run is important, because it proves that all primes have a deterministic ...
7
votes
5
answers
2k
views
Prime number finder below the limit specified
Is this an optimal solution? I doubt it is. Can someone please critique my code?
...
11
votes
3
answers
2k
views
Computing π(x): the combinatorial method
This is my C++ implementation of Computing π(x): the combinatorial method by Tomás Oliveira e Silva. The math involved is elementary number theory, but fiddly and not the focus here. I have ...
3
votes
1
answer
115
views
Optimizing sieving code for the Multiple Polynomial Quadratic Sieve
I wrote code for the multiple polynomial quadratic sieve (MPQS) here:
...
4
votes
2
answers
240
views
Simple Sieve of Eratosthenes
I've implemented this version of the Sieve of Eratosthenes in Rust, with inputs. I'm mostly pleased with it, but want to know if the input logic can be simplified, and if the sieve itself can be ...
2
votes
1
answer
186
views
What is the most efficient way to figure out if a single number is prime for numbers from 2 up to 2,147,483,647 in Java?
As Java programmers, we can always use the BigInteger isProbablePrime() method or store manually all prime numbers in a HashMap. This question is about the most efficient way to figure out if a single ...
6
votes
3
answers
926
views
Project Euler 127 - abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
We shall ...
6
votes
0
answers
125
views
Optimizing SymPy Implementation of prime factorization in form of QUBO
I'm trying to reproduce a paper on Prime Factorization. This paper converts the problem into a QUBO form, which then we can map it to an Ising Minimizer. I've basically done everything and I've ...
2
votes
1
answer
195
views
Count how many numbers in a range have exactly three divisors
The challenge
Given array a of n numbers, I need to count how many positive numbers less than each aᵢ have exactly 3 divisors.
Constraints
1 <= aᵢ <= 2.5 * 10¹³
In other words,
the minimum ...
8
votes
4
answers
529
views
Optimal Solution for the Four Divisors Problem on LeetCode
I recently encountered the Four Divisors problem on LeetCode and managed to achieve a 100% beat rate with my solution. I'd like to share it with you all and gather feedback on its effectiveness and ...
3
votes
1
answer
178
views
Miller-Rabin implementation is very slow
I implemented the Miller-Rabin-Primetest in python3. But I have the feeling it is very slow. I know that there are faster version in gmpy2 package, but I want to compare it with another code I have in ...
1
vote
2
answers
158
views
Miller-Rabin prime test
I have an implementation of the Miller-Rabin prime test, coded in Python 3.
I want to use that as a comparison to a prime test which I coded myself.
Unfortunately I have no idea how "fast" ...
9
votes
1
answer
341
views
Construct a performant sieve of Atkin in Rust
I have implemented the sieve of Atkin in Rust. It can find all primes till 1,000,000,000 in 4.5 s using 34.4 MiB on my 1.4 GHz machine. This is a direct implementation (with some optimisations made ...
6
votes
2
answers
1k
views
C code for finding prime numbers
I have created a program to find prime numbers up to the 32nd power of 2. It uses the sieve of Eratosthenes. I would appreciate it if you could let me know any bugs or improvements I can make.
...
1
vote
1
answer
143
views
Project Euler 10(Python) | Summation of Primes
This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases.
...
3
votes
1
answer
378
views
Project Euler 60: Prime Pair Sets
Project Euler Prime Pair Sets:
The primes 3, 7, 109, and 673 are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime.
For example, taking 7 ...
3
votes
1
answer
120
views
Find perfect and amicable numbers
I've been playing with perfect, amicable and social numbers lately, and created a class for investigating these. At present, it has functions to return the perfect and amicable numbers in a specified ...
4
votes
2
answers
2k
views
Miller-Rabin Primality Test in Python
I have the following implementation of the Miller-Rabin test in Python:
...
4
votes
2
answers
775
views
Performance of Haskell prime sieve
I have this code, which is a pseudo-Sieve of Eratosthenes for generating primes:
...
3
votes
1
answer
168
views
Hunting for the 100,001st prime in Rust
Most of my programming experience is in Python, but my first language was C, and I was intrigued by the combination which Rust offers: a streamlined syntax and no manual memory management, but with ...
2
votes
2
answers
181
views
generate prime factors via wheel factorization
I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
3
votes
1
answer
156
views
Prime sieve in Rust
Using Sieve of Eratosthenes, I created a function that returns a vector of primes up to given limit.
...
17
votes
4
answers
2k
views
Make an image where pixels are colored if they are prime
This code creates a black-and-white image of variable size where the n-th pixel is white if n is a prime number and black if it isn't. It works, but I wonder if it is well written or if it could be ...
3
votes
1
answer
251
views
Find factor pairs of an integer in Rust
I'm trying to efficiently generate all pairs of factors of a number n.
For example, when n=27, the factor pairs are (1, 27), (3, 9), (9, 3), (27, 1)
The order in which the pairs are found is not ...
3
votes
1
answer
125
views
Strong Goldbach Conjecture with set implementation
I have devised my own version for a Goldbach verification project which uses sets to compare already sieved primes. My implementation also uses generators to "sieve a segment" since storing ...
4
votes
1
answer
628
views
Prime factorization algorithm by using the multiprocessing module of Python
I may introduce a Python code of prime factorization which is from my personal project that I'm working on.
...
1
vote
1
answer
167
views
Numpy segmented Sieve Of Eratosthenes
For the segmented Sieve Of Eratosthenes, I have devised the following code provided. And I understand that it is not the best implementation; However, it should be much quicker than what it is now. ...
3
votes
1
answer
274
views
Find primes using Wilson's Theorem
The following code is an instantiation of wilson's theorem. It uses a simple factorial and division theorem to check for primality. My issue is with the performance of the code, and there are two most ...
5
votes
1
answer
130
views
Möbius function using iterators for prime factors
While working on Project Euler, I have come across a few questions involving usage of the little omega function, big omega function, and Möbius function.
My prior code wrote factors into an array and ...
2
votes
1
answer
151
views
Multithreaded segmented Sieve of Eratosthenes
I am fairly new to Rust and thought a good way to practice would be to write a multithreaded segmented Sieve of Eratosthenes. It performs ok (searches ten-billion numbers in about 11 seconds on my ...
1
vote
1
answer
210
views
Euler's totient function for large numbers
I made this algorithm to compute Euler's totient function for large numbers. A sieve is used.
...
2
votes
1
answer
353
views
Prime sieve for large numbers
I state that I am not an expert and that certainly the code can be improved.
I made this prime number sieve to be able to handle large numbers.
The basic idea is to write a number p=r+bW*k where r is ...
0
votes
1
answer
226
views
Find factors of a Mersenne number
On RosettaCode I found this C++ version of modPow (compute 2ᵖ mod n) to find the factors of a Mersenne number.
...
0
votes
2
answers
768
views
Next level Improved Sieve of Eratosthenes
This is the next development for the Sieve of Eratosthenes algorithm, where all the multiples of 2,3 and 5 are eliminated, which will not take any memory or time.
As my last question Improved Sieve of ...
7
votes
7
answers
4k
views
Improved Sieve of Eratosthenes
How can I get to a perfect coding for this algorithm?
I made the mathematical theorem, which is a development of the Sieve of Eratosthenes algorithm. I might use some help in coding.
You can find the ...
5
votes
2
answers
265
views
Project Euler #51: "Prime digit replacements" in Rust
Problem: https://projecteuler.net/problem=51
"Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime ...
3
votes
1
answer
144
views
Fast way to compute a^d mod n
For a Miller-Rabin primality test I need a fast way to compute a^d mod n.
Where a is one of 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...
5
votes
2
answers
1k
views
Calculate the first largest factor of 600851475143
ٍProblem description:
The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29.
What is the largest prime factor of the number 600851475143 ?
Prime Factor:
any of the prime ...
3
votes
3
answers
192
views
Count SemiPrimes task from Codility
I'm trying to solve the following exercise from Codility:
A prime is a positive integer X that has exactly two distinct
divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and
13.
A ...
1
vote
2
answers
261
views
Clojure Prime Numbers from 1 to 1000
I am a beginner to Clojure and I made a little script that prints out every prime number from 1 to 1000. Let me know if there are any improvements that I can make:
...
3
votes
1
answer
177
views
A simple JavaScript function that does prime factorization
This is a simple JavaScript function that does prime factorization.
I wrote it on an Android phone with online editor (I don't have access to computers in night time):
Code:
...
2
votes
3
answers
450
views
Find prime numbers
I wanted to create a program that lists all prime numbers to a given upper bound and that will also provide the amount of primes in the set. After many hours of trial and error I was able to solve it.
...
3
votes
0
answers
283
views
Prime number generator in lisp
My implementation is based on the incremental prime sieve described on Wikipedia. I'm relatively new to lisp so I would appreciate any comments on my coding style or on the algorithm.
The below code ...
1
vote
1
answer
90
views
C code for discovering numbers with interesting/beautiful/symmetric properties
Below is a C code that generates 1000 random positive integers, for each number we check primality, palindromic property, and the square root of the sum of the digits. The purpose is to find/discover ...
3
votes
2
answers
177
views
Factor 999999 numbers as fast as possible
My code finds the prime factorization of numbers, ordering the prime numbers from least to greatest.
It prints a list of 999999 prime factorizations (which can be changed if you edit the function call ...
2
votes
1
answer
206
views
Sieve of Eratosthenes in F#
after looking at the pseudocode for the Sieve of Eratosthenes on wikipedia I tried implementing a similar version using F#. The code runs just fine, that is, it returns all prime numbers up until a ...
3
votes
2
answers
452
views
Prime numbers iterator
I am not familiar with iterators. I am confused with the traits approach and the traditional one. I don't know which one I should use in 2021.
I wrote a minimal ...