Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

0
votes
0answers
36 views

Greatest prime factor [closed]

Code: (edits are appreciated) ...
4
votes
1answer
101 views

Sieve of Eratosthenes in Python

This is yet another take in Python for the infamous Sieve of Eratosthenes. I am a beginner in Python so any criticism is highly appreciated. ...
10
votes
4answers
693 views

Calculating primes until a user-given value

I am new to C# programming. I wrote a little program in C# to calculate all primes until a user-given value. Ignoring the lack of computing power I wrote this program to handle theoretically very huge ...
3
votes
2answers
92 views

Show all primes in go

I'm trying to go through Adrian simple programming tasks; Elementary task 8 It's basically asking for an infinite loop to print every prime number as it finds it. Are there too many ...
3
votes
1answer
34 views

Prime number sieve in Standard ML

As practice, I have written a prime number sieve in Standard ML. It works in a pretty straightforward way: The list of known primes starts with just 2. Starting with 3, check whether each odd ...
15
votes
5answers
5k views

Python 3: Why is my prime sieve so slow?

I've implemented the sieve of Eratosthenes in Python 3 as follows: ...
2
votes
1answer
119 views

Project Euler: Find 10.001st prime

I have just started learning C# and decided to do some problems from Project Euler. I wrote a code to find 10 001st prime and I thought it would be cool optimize it to make it as fast as possible. How ...
2
votes
0answers
38 views

Haskell function to generate prime numbers up to argument [closed]

I made a function to generate a list of prime numbers using list comprehensions. Here it is: ...
2
votes
1answer
67 views

Prime numbers generator

This is a prime numbers generator class, loosely based on the sieve of Eratosthenes. It is supposed to generate a decent quantity (i.e. millions) of prime numbers. ...
1
vote
0answers
53 views

Get prime divisors of an Int32 using a wheel

I recently played around with prime factorization using a prime wheel. Much of the heavy lifting is done by the PrimeWheel class. I think the implementation is ...
2
votes
2answers
588 views

Function to check whether entire list is prime numbers

I have a prime function which accepts a list of numbers and checks if all of the numbers in the list are prime. Here is my code: ...
10
votes
4answers
1k views

Find the sum of prime numbers below 2 million

This code is trying to find the sum of prime numbers below 2 million. The code does work as intended, but it takes a very long time ( 6 minutes) for the code to execute completely. What is the problem ...
0
votes
1answer
54 views

Find primes using Sieve of Eratosthenes with Python

I was Googling for a 'correct' or 'efficient' implementation of the Sieve of Eratosthenes. I found them all more complicated than what I came up with. I am by no means a Python expert, so I was ...
11
votes
2answers
835 views

Express a number as sum of 2 primes

Problem: Given an even number (greater than 2), return two prime numbers whose sum will be equal to given number. NOTE 1: A solution will always exist. (Goldbach's conjecture) Note 2: If ...
2
votes
1answer
33 views

Display all Prime Factors from user input

The following program is written in python. Is there a more efficient way to write this program? Suggestions and criticism are welcome. You can also comment about my variable naming practices and code ...
5
votes
3answers
123 views

Outputting prime numbers in given ranges

I coded an algorithm which shows prime numbers in the ranges provided by the user. The first line states the number of test cases. Example: INPUT 2 1 10 1 5 ...
8
votes
1answer
163 views

Prime Number Generator & Efficiency

If anyone can explain to me the advantages of using things like the Sieve of Atkin over the Sieve of Eratosthenes, and how to code it (especially the Sieve of Atkin), that would be highly appreciated. ...
11
votes
2answers
2k views

Find prime factors in C++

Please review this code. ...
8
votes
4answers
135 views

Searching for pairs of integers that satisfy primality and divisibility conditions

I wrote a program in Python 3 to check all tuples of the form (s,t) where s and t are ...
4
votes
1answer
40 views

Calculate Mersenne prime numbers in MATLAB

A Mersenne prime is equal to (2^n - 1), where n is an integer. 31 is a Mersenne prime since 31 = 2^5 -1. I need to write a code that calculates Mersenne primes between 1 and 10,000. Lastly I'm not ...
25
votes
2answers
2k views

Euler's Totient Function in x86 assembly (MASM)

My task was to implement Euler's totient function, and I'm looking for any and all criticism. ...
6
votes
5answers
286 views

Python prime number checker function

I was bored, and I was watching a sci-fi show where people were starting out during a long systems check asking each other whether numbers were prime or not, sort of passing the time as they do their ...
2
votes
1answer
69 views

Is It In Its Prime?

Just because I'm bored, I wrote yet another prime number generator. I think it's pretty clean, but I won't be surprised if someone finds something to comment on. ...
14
votes
5answers
4k views

Nearly Illegible Prime Number Calculator

This is my first reasonably large C# program. Considering my code looks like it was written in an esolang to me, I'm guessing I did something wrong at some point. My main priority is readability, ...
5
votes
2answers
88 views

Returning the prime factors of a number

I am trying to create a function prime-factors that returns the prime factors of a number. To do so, I created is-prime function,...
3
votes
1answer
97 views

Counting primes in given interval

So, here is a Hackerearth question, regarding (more or less) counting the number of primes between a given pair of numbers (up to 106). Then there were 3 major options available to me: Trial ...
-3
votes
1answer
77 views

Closest Prime Number via Letters [closed]

I'd like this code to be optimized and factorized, along with, perhaps, re-making it so it's more readable via introducing better functions and minimizing the lines needed for it to be human-readable (...
5
votes
1answer
237 views

Goldbach's Conjecture

I am doing an exercise on finding the nearest pair of prime numbers p₁ and p₂ such that: p₁ ≤ p₂ p₁ + p₂ = n (for 4 ≤ n ≤ 10⁷) p₁ and p₂ are primes p₂ - p₁ is minimal I think it should work ...
3
votes
0answers
237 views

Miller-Rabin Primality Test Using C++ and GMP

I'm currently writing a Miller-Rabin primality test using C++ and the GNU MP Bignum Library (GMP). As I've only started learning C++ about a day ago, I'm sure this code is riddled with errors and ...
2
votes
1answer
89 views

Mocking an F# primality tester

I would like to ask 2 questions about the modularization of an F# file. The code is just a working example of prime factorization, but that's not the main topic. I have a main file (PrimeFactors.fs), ...
2
votes
4answers
81 views

Generating N Prime Numbers

I'm trying to generate N prime numbers where my N = 200,000. The method that I think I wrote is - Start with first prime of 2 Increment possible prime number by 1 See if possible prime is ...
4
votes
1answer
131 views

Optimizing Miller-Rabin Primality Test in Python

I'm writing a Miller-Rabin primality test in Python. While I've briefly looked at how others approached the problem, I decided to try solving the problem on my own. Aside from my choice of language, ...
5
votes
1answer
618 views

C++ RSA Implementation

A while ago I wrote an implementation of RSA with C++, that takes in a simple string,encrypts and then decrypts it. It's pretty much the only substantial thing I have written in C++ and while it works ...
7
votes
2answers
286 views

Project Euler 357 prime number generator in Python 3

I'm brute forcing the Project Euler 357 since no better algorithm comes to my mind. The challenge asks: Find the sum of all positive integers n not exceeding 108 such that for every divisor d of n, ...
9
votes
4answers
479 views

Project Euler Problem #7 in Python (10001st prime number)

I have managed to solve the 7th Project Euler problem, however I think it can be improved by a lot, I am by no means a professional programmer or even consider myself really good at it. Any ...
1
vote
1answer
46 views

Prime reversion algorithm - JavaScript

I solved the following problem: Consider the range 0 to 10. The primes in this range are: 2, 3, 5, 7, and thus the prime pairs are: (2,2), (2,3), (2,5), (2,7), (3,3), (3,5), (3,7),(5,5), (5,7), (7,7)....
2
votes
1answer
124 views

Find the probability of picking a prime number in a range

The task is: From a sub-sequence of integers between 2 inputted numbers A and B, we need to find the probability of picking a prime number. I have written something to accomplish the task- ...
2
votes
0answers
47 views

Kotlin sieve using sequences

While learning about functional programming the simple sieve example was brought up in Haskell. I wanted to try a Kotlin implementation using sequences. Are there any other quick wins without ...
1
vote
1answer
761 views

code to check if number is prime number

I have written a code to check if the number is prime number are not. I pass the number from command line argument, and check if the number is prime. I have written a function for it which returns ...
4
votes
2answers
115 views

Project Euler #196: Prime triplets

I did the HackerRank version of Project Euler #196 using Python 3. My code ran successfully for 6 test cases out of 20. For test 14, it showed a timeout error which is not a functionality bug but ...
2
votes
2answers
127 views

Primality predicate in Haskell

I wrote a primality test for UniHaskell however, it seems complicated in terms of conditionals. Here it is, rewritten to not use Unicode and other functions in the code: ...
3
votes
1answer
89 views

Find primes faster (Java)

I'm new here, and relatively new to coding. I wrote a method that returns an array of the n first primes. Even though my intended goal was just to find the nth prime, I ended up using an array (int[] ...
0
votes
1answer
92 views

Finding the first 10 million primes

I'm trying to find the first 100 million primes and am trying to find the most efficient way to do it. Can I get some advice on how I could improve this? ...
4
votes
0answers
78 views

Cached infinite prime generator

For a project I am working on, I need to use a lot of primes, frequently. To do this, I added a cache to Will Ness's prime sieve, that stores already generated primes so getting them is quick. How can ...
6
votes
1answer
95 views

Python3 - Prime Sieve

I've implemented two prime sieves in python 3 to find all prime numbers up to an upper limit n - n exlusive. The first one is ...
6
votes
1answer
169 views

Maximum performance for Pollard's P-1 function

I am trying to find mersenne primes using python, and following the advice from https://www.mersenne.org/various/math.php, I have an intermediate step where I am using Pollard's P-1 factoring ...
3
votes
3answers
311 views

Checking whether a number is a Smith number

I have created a Java program to check if the number entered by the user is a Smith number (a number whose sum of digits equals the sum of the digits of its prime factorization). The program works ...
3
votes
1answer
83 views

Third project Euler solution

The things I'm interested the most from the review are: The performance of the code Overall review of the code structure, styling rules and naming conventions. What is the largest prime factor of ...
5
votes
3answers
222 views

Finding as many perfect numbers as possible

I have tried to make a perfect number finder as efficient as possible in python. If anyone has any things I can add to make it more efficient or any problems with my code please say. ...
2
votes
2answers
74 views

Pythonic Prime Generation

I am using a sieve to return all primes under N: ...