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)

2
votes
1answer
47 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
42 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
62 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
51 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
35 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
66 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
84 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
37 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
69 views

First n primes optimization

Pretty standard. Generates the first n primes, input via a scanner. ...
1
vote
2answers
68 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
85 views

Postponed Prime Sieve in Swift

Motivated by Unbounded Sieve of Eratosthenes in Swift, 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 ...
3
votes
1answer
79 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
58 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 ...
2
votes
1answer
67 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
85 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
0answers
24 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
51 views
7
votes
2answers
756 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
75 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 ...
9
votes
3answers
270 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
108 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
27 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
564 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
34 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
121 views

Snakes on a prime

The challenge is to find and print the largest palindrome prime under 1000. ...
1
vote
1answer
94 views

C++ Prime Number Library

This prime number library is one of my first programming projects I've done in c++. My goal is to create useful functions that deal with prime numbers in an efficient way.Note: (Most of the functions ...
6
votes
1answer
112 views

C the sum of primes

The challenge is to calculate the sum of the first 1000 primes. The code applies a sieve thanks to past answer, here, and works but I wonder about the flexibility of this solution. ...
3
votes
1answer
111 views

Prime number checker in Python 3 - follow-up

I have updated my code from the last time it got reviewed. If anyone has some more suggestions on how I can improve this and/or make it faster it would be appreciated! ...
10
votes
5answers
854 views

Largest Prime Factor (PE3) using OOP

I want to learn some C# syntax/paradigms (I'm more used to Java), and have been wanting to get a bit better at math as well, so I solved ProjectEuler3: Largest prime factor with the following small ...
4
votes
2answers
73 views

Prime number calculator in Python 3.4.1

I have only been coding for a short time and I have written these two functions and am looking to optimise them. If anyone could point out things that could be done better it would be much appreciated....
-1
votes
3answers
111 views

Shortest prime number generator we could come up with?

I worked with a friend on the following prime number generator. Our goal was to make it as short and as fast as possible. This is what we came up with: ...
4
votes
3answers
587 views

Project Euler 10: find the sum of all the primes below two million

This is question #10 from Project Euler: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. I just started programming and read that a Sieve ...
1
vote
1answer
103 views

Check if a number is prime

I'm looking for feedback on the following code which checks if a number is prime using Swift 2. ...
0
votes
1answer
293 views

Project Euler #50 Consecutive prime sum

I'm having trouble optimising the project euler #50 exercise, it runs for around 30-35 seconds, which is terrible performance. The prime 41, can be written as the sum of six consecutive primes: ...
3
votes
1answer
110 views

Finding the prime factors of a positive number

I have an assignment to write on the standard output the prime factors of a positive number displayed in ascending order and separated by '*'. My code works, but I need help reviewing it before I ...
3
votes
2answers
113 views

Project Euler #49 Prime permutations

Today I solved problem #49 from project euler .net which reads : The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the ...
2
votes
3answers
91 views

Non-Sieve Prime Number generator

...
-1
votes
2answers
75 views

Prime Number Generator

The purpose of this program is to run an infinite prime generator that won't stop unless I tell the console to stop. This is not a sieve of Eratosthenes; it stores prime numbers in an array and ...
2
votes
3answers
159 views

Calculate the sum of all primes less than 2,000,000 in Swift

This is a Swift program I wrote to calculate the sum of primes below 2 million, but it is tediously slow. I am curious about what makes it so slow. My theory is that copying the filtered array is ...
5
votes
0answers
33 views

Multiple rusty Sieves of Eratosthenes

To get more familiar with the multi-threading aspects in the Rust language I decided to multi-thread my earlier implementation of The rusty Sieve of Eratosthenes. I have to say that it is probably in ...
3
votes
1answer
63 views

Symmetry analysis for atom arrangements in a crystal

For a while now I've been meaning to post some of my Haskell code here so that someone can tell me what parts of the language/base library I've been completely overlooking. This is the first thing I'...
4
votes
1answer
128 views

Number of divisors of a factorial

I was solving the DIVFACT problem from Sphere Online Judge: Given a number, find the total number of divisors of the factorial of the number. Since the answer can be very large, print the answer ...
1
vote
1answer
82 views

SICP exercise 1.28 - miller-rabin primality test

From SICP Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; Rabin 1980). This starts from an alternate form of Fermat’s Little ...
1
vote
1answer
67 views

Fast nth prime in Python using trial division

I'm trying to speed this code up for larger values of N. Any suggestions? I'd like to stick to this implementation and not move on to something more complex like numpy or sieves. Is there any low ...
6
votes
1answer
114 views

The rusty Sieve of Eratosthenes

To get familiar with the Rust language I've decided to implement the method of Sieve of Eratosthenes to find primes up to a number N. I have created the following code that both prints the prime ...
3
votes
2answers
366 views

Printing all prime factors of a number input by the user

I just started teaching myself to code a few days ago using the Euler problems. I finished a variant of problem 3: print the prime factors of a number input by the user. I just want feedback and code ...
2
votes
1answer
117 views

Primes & Squares

Codeforces #230B Question Whether a number has exactly three factors. (i.e. 1, itself and its square root, thus squares of primes) [Time limit is 2 sec, Memory 256 MB] Input Number of testcases, n ...
3
votes
3answers
102 views

Counting the number of primes in C and C++11

I found this old piece of code that I wrote while I was learning C a while back: ...
3
votes
1answer
39 views

Writing a Rustic segmented prime number sieve

I wrote a prime number sieve in Ruby last year as part of a coding challenge, but lately I wanted to port it to Rust. I finally got around to it, but it's still intensely Rubinic. Before I take the ...
1
vote
1answer
76 views

Prime generator SPOJ problem in Python 3

I am trying to solve an SPOJ problem: print all prime numbers in a given range (as large as \$10^9\$). I have used the Sieve of Eratosthenes algorithm. But it is still slow when input is in range of \$...