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.

learn more… | top users | synonyms (1)

8
votes
3answers
816 views

Project Euler Problem 35: counting circular primes below 1 million

Project Euler Problem 35 asks: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. How many circular primes are there ...
1
vote
1answer
50 views

Prime factorization - C

After learning prime factorization today, below is the C code written, ...
-1
votes
1answer
71 views

Largest prime factor of a given number

I'm solving Problem 3 in Project Euler: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? Most answers I found made use of array to ...
3
votes
3answers
136 views

Prime factoring function using recursion

As a programming exercise, I decided to make a prime factoring function using recursion: ...
1
vote
2answers
56 views

Infinite prime generator

This code acts as an infinite generator of prime numbers. As new prime numbers are found, they are added to a set. Then, a number x is found to be prime if none of the numbers in the prime set are ...
5
votes
2answers
198 views

Yet Another, Another Prime Generator

Yes, I realize there are many, many, many, many, many, prime generators on the Code Review SE. However, I have been unable to find any using this method for generating primes inside a vector, so I ...
1
vote
0answers
12 views

Finding the largest p-adic order of a given integer [closed]

I need to find the highest P-adic order - that is the largest power among the powers of primes in the prime factorization of an integer - of large integers . The only - and naive - approach I ...
2
votes
0answers
25 views

Mersenne Prime Checker using Lucas-Lehmer Formula

Previously I created a C# script that used trial division to check to see whether or not certain Mersenne numbers were prime. Since these numbers are so big, I employed some math shortcuts to reduce ...
12
votes
2answers
3k views

Project Euler #10 in C++ (sum of all primes below two million)

Project Euler Problem 10 asks for the sum of all the primes below two million. I'm creating a list of primes and keep checking any new number for divisibility with only prime numbers. I thought it ...
3
votes
2answers
162 views

Mersenne Primes Generator in C#

I've made a program in C# that generates Mersenne numbers starting from the current largest known Mersenne prime. It then calculates the modulo between those numbers and smaller ones starting from 3 ...
1
vote
0answers
48 views

Custom Sieve of Eratosthenes in C++

I'm trying to improve my code to find all the prime numbers within a set range as fast as possible, and I am trying to make it even faster. On my github page here, I have some optimization settings ...
2
votes
1answer
78 views

List of all prime factors of a number, including repeats

This code will return a list of the prime factors of n, and the prime factors are repeated so that the product of the list is equal to n. ...
4
votes
2answers
139 views

Sieving for prime numbers

I wanted to implement the Sieve of Erathosthenes up to int.MaxValue in C#. No object is allowed to exceed 2Gb so you can't allocate a ...
1
vote
4answers
167 views

Calculate prime numbers

This is a program to calculate the largest prime number. Are there any possible improvements in style/speed/accuracy? ...
5
votes
6answers
165 views

Project Euler #3 in C# - largest prime factor

I just started doing the Project Euler challenges and right now I'm on Challenge #3 - The largest prime factor of 600851475143. I wrote some code and tried to optimize it based on some other Stack ...
3
votes
1answer
57 views

Project Euler #58: Primes along the diagonals of a square spiral

I am working on Project Euler Problem 58: Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed. ...
6
votes
1answer
171 views

Down to Zero II

Problem : https://www.hackerrank.com/challenges/down-to-zero-ii You are given queries. Each query consists of a single number N. You can perform 2 operations on N in each move. If N=a*b (a!=1,b!=...
1
vote
2answers
91 views

Project Euler Problem #3 in Java - Largest Prime Factor

I have solved the problem and it gives me the right output when the BigInteger has the smaller value, however it kept running for more than 20 minutes with the ...
7
votes
4answers
160 views

Python Prime Testing

This code seems surprisingly fast at checking if a number is prime. ...
2
votes
1answer
59 views

Efficient Prime Sieve - Haskell

I'm new to Haskell, and am trying to learn the basics with a simple function that will calculate the list of primes up to a given value (using the Sieve of Eratosthenes). Here is my code so far, which ...
3
votes
3answers
99 views

Lucas sequence implementation

Could you suggest any improvements in this Lucas sequence's implementation: ...
2
votes
3answers
386 views

Finding out the prime factors of a number

This finds the prime factors of a number given in a variable. Is it efficient or in need of improvement? ...
3
votes
2answers
65 views

Testing Goldbach's Conjecture hypothesis

A book1 that I'm reading states Goldbach's conjecture as follows: Every even integer > 2 could be represented as a sum of two prime numbers. Every integer > 17 could be represented as a sum of ...
2
votes
1answer
40 views

Postponed Prime Sequence in Kotlin

Following my previous unbounded prime generator and a followup by Martin R, I've tested the waters in Kotlin by making an unbounded sieve. To quote Martin R's wonderful explanation of the base ...
3
votes
1answer
95 views

SICP exercise 1.28 - miller-rabin primality test part II

This is a follow-up to SICP exercise 1.28 - miller-rabin primality test. Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; ...
2
votes
1answer
80 views

Generating numbers that are a product of consecutive primes

I have implemented a correct but horribly coded solution to Project Euler Problem 293. An even positive integer N will be called admissible, if it is a power of 2 or its distinct prime factors ...
1
vote
1answer
56 views

Project Euler 12 (triangle numbers), solved using functools.reduce() and looping

I have solved problem 12 on Project Euler website, which reads: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 +...
3
votes
2answers
99 views

Simple Input Text Analysis

I've started learning java. I've written a small program I've done in C before. It's simple input analysis. If there is number, program checks if number is prime. Then write number: (value of input ...
1
vote
2answers
72 views

Multithreaded brute force prime generator

A number is a prime when it is divisible by 1 and the number itself. To check if a given number is a prime we can divide the number by primes which are less than the square root of that number. If ...
2
votes
1answer
46 views

Stateful prime_numbers class for searching and storing primes

Title says the biggest part. The class is designed to be used to search for very big prime numbers, hence the element type is templated. The performance, neither in space nor time, is considered. ...
3
votes
3answers
75 views

Check if given number can be expressed as sum of 2 prime numbers

Similar problem: Sum Of Prime I've done the given problem in roughly \$\mathcal{O}(n\sqrt{n})\$. How can I improve this algorithm? ...
2
votes
2answers
187 views

Find prime numbers from 1 to 100

Create a program to find all the prime numbers between 1 and 100. One way to do this is to write a function that will check if a number is prime (i.e., see if the number can be divided by a prime ...
1
vote
1answer
42 views

Simple Factor Class

I have a class which lazily factors numbers. It provides the user with these methods: getFactors returns a ...
3
votes
3answers
72 views

First n primes optimization

Pretty standard. Generates the first n primes, input via a scanner. ...
1
vote
2answers
75 views

Another Python prime-listing algorithm

I wrote a small program in Python that finds primes (how original) up to some limit. I tried to produce very clean code, so I'd be vary grateful if you could point out any improvement I could do to ...
5
votes
2answers
149 views

Postponed Prime Sieve in Swift

Motivated by this question, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an a-priori upper limit (such ...
3
votes
1answer
110 views

Find the 10001st prime number (in C++)

I wrote this solution for project Euler #7, to find the 10001th prime number using sieve of eratosthenes. It's really slow though. Any suggestions to improve performance (without using more complex ...
1
vote
1answer
115 views

Unbounded Sieve of Eratosthenes in Swift

I've spent a while teaching myself Swift, and decided to take on the challenge of writing an unbounded Sieve of Eratosthenes to challenge myself. This is actually the first time I've written an ...
1
vote
3answers
145 views

Finds all the prime numbers up to n using a strange pattern

Here's an odd pattern I found for sieving out composite numbers to find primes. I wrote it myself, originally thinking I made an indexing error, but it turned out to work after removing squares. <...
7
votes
2answers
109 views

Sieve of Eratosthenes and twin prime finder

I made this program to find primes and twin pairs. I'd like feedback on anything from formatting to content to technique. In short: how would this be different if it was written by an experienced ...
3
votes
1answer
60 views

The Miller-Rabin Primality Test in Clojure

I am new to clojure and I wanted to test out my skills by taking an existing implementation written in Python and writing it in Clojure. Concerns My main concerns are where I use ...
1
vote
1answer
60 views
7
votes
2answers
766 views

Looking for primes with all-different digits

I recently answered a question on Mathematics Stack Exchange, where I used a small Python program to check the following : For all 6-digit numbers, with all digits being different, choosing the ...
0
votes
0answers
77 views

Computation of primality

I believe I have achieved computation of primality! That is, the computation of prime numbers. The code I am about to post will give you every prime there is, in order, starting with 2. Can we call ...
10
votes
3answers
276 views

PrimeFactorize method for int

I have written this PrimeFactorize utility method in C# (using LINQPad) which works fine, but feels like it is a bit slow, I was wondering what might be improved. ...
1
vote
1answer
110 views

Approaching a C++ library with templates

I previously posted a thread asking for a general review of one of my first projects related to programming (C++ Prime Number Library) and received very good help and new perspectives. After this, I ...
3
votes
1answer
52 views

TLE on SPOJ for Prime Generator (PRIME1)

The objective is to find all primes between two given numbers. It is specified that the two numbers are \$\le\$ 1 billion and the difference between the two numbers is ~100,000. We are to repeat the ...
5
votes
4answers
603 views

Project Euler 3: Largest prime factor

How can I improve my code, make it more efficient, and are there any tips you have? Project Euler 3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the ...
0
votes
0answers
39 views

Palindromic prime search using the Sieve of Atkins

I am working on a project that deals with prime numbers and am currently looking for a way to make the function max_palprime() work faster and possibly simpler. ...
5
votes
3answers
132 views

Snakes on a prime

The challenge is to find and print the largest palindrome prime under 1000. ...