Skip to main content

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.

Filter by
Sorted by
Tagged with
9 votes
4 answers
809 views

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 ...
mezzoctane's user avatar
3 votes
1 answer
178 views

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 ...
dragoness's user avatar
  • 317
5 votes
1 answer
472 views

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"...
dragoness's user avatar
  • 317
10 votes
2 answers
1k views

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 ...
dragoness's user avatar
  • 317
7 votes
5 answers
2k views

Is this an optimal solution? I doubt it is. Can someone please critique my code? ...
FirstTimer's user avatar
11 votes
3 answers
2k views

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 ...
qwr's user avatar
  • 1,233
3 votes
1 answer
115 views

I wrote code for the multiple polynomial quadratic sieve (MPQS) here: ...
J. Doe's user avatar
  • 186
4 votes
2 answers
240 views

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 ...
Vessel's user avatar
  • 345
2 votes
1 answer
186 views

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 ...
user3595831's user avatar
6 votes
3 answers
926 views

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 ...
Nadav Nevo's user avatar
6 votes
0 answers
125 views

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 ...
Amirhossein Rezaei's user avatar
2 votes
1 answer
195 views

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 ...
Muhammad Usman's user avatar
8 votes
4 answers
529 views

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 ...
BrunoBarreto's user avatar
3 votes
1 answer
178 views

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 ...
Lereu's user avatar
  • 141
1 vote
2 answers
158 views

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" ...
Lereu's user avatar
  • 141
9 votes
1 answer
341 views

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 ...
tfpf's user avatar
  • 193
6 votes
2 answers
1k views

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. ...
Haruo Wakakusa's user avatar
1 vote
1 answer
143 views

This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases. ...
peternish's user avatar
3 votes
1 answer
378 views

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 ...
peternish's user avatar
3 votes
1 answer
120 views

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 ...
Toby Speight's user avatar
  • 88.7k
4 votes
2 answers
2k views

I have the following implementation of the Miller-Rabin test in Python: ...
phlatfish's user avatar
4 votes
2 answers
775 views

I have this code, which is a pseudo-Sieve of Eratosthenes for generating primes: ...
Ari Fordsham's user avatar
3 votes
1 answer
168 views

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 ...
Tom Hosker's user avatar
2 votes
2 answers
181 views

I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
Kittoes0124's user avatar
  • 1,960
3 votes
1 answer
156 views

Using Sieve of Eratosthenes, I created a function that returns a vector of primes up to given limit. ...
manungsa's user avatar
  • 107
17 votes
4 answers
2k views

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 ...
Dornteufel's user avatar
3 votes
1 answer
251 views

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 ...
Bram's user avatar
  • 93
3 votes
1 answer
125 views

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 ...
Kevin Perez's user avatar
4 votes
1 answer
628 views

I may introduce a Python code of prime factorization which is from my personal project that I'm working on. ...
MYUN's user avatar
  • 59
1 vote
1 answer
167 views

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. ...
Kevin Perez's user avatar
3 votes
1 answer
274 views

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 ...
Kevin Perez's user avatar
5 votes
1 answer
130 views

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 ...
Ethan Slota's user avatar
2 votes
1 answer
151 views

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 ...
knots427's user avatar
1 vote
1 answer
210 views

I made this algorithm to compute Euler's totient function for large numbers. A sieve is used. ...
user140242's user avatar
2 votes
1 answer
353 views

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 ...
user140242's user avatar
0 votes
1 answer
226 views

On RosettaCode I found this C++ version of modPow (compute 2ᵖ mod n) to find the factors of a Mersenne number. ...
user140242's user avatar
0 votes
2 answers
768 views

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 ...
Ahmed Diab's user avatar
7 votes
7 answers
4k views

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 ...
Ahmed Diab's user avatar
5 votes
2 answers
265 views

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 ...
sarema's user avatar
  • 499
3 votes
1 answer
144 views

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, ...
Goswin von Brederlow's user avatar
5 votes
2 answers
1k views

ٍ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 ...
Amir Motefaker's user avatar
3 votes
3 answers
192 views

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 ...
Karol Borkowski's user avatar
1 vote
2 answers
261 views

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: ...
code writer 3000's user avatar
3 votes
1 answer
177 views

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: ...
Ξένη Γήινος's user avatar
2 votes
3 answers
450 views

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. ...
Lax's user avatar
  • 21
3 votes
0 answers
283 views

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 ...
rose's user avatar
  • 325
1 vote
1 answer
90 views

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 ...
Redsbefall's user avatar
  • 1,212
3 votes
2 answers
177 views

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 ...
Some Guy's user avatar
  • 131
2 votes
1 answer
206 views

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 ...
Antônio Salomão's user avatar
3 votes
2 answers
452 views

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 ...
nowox's user avatar
  • 1,121

1
2 3 4 5
15