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)

0
votes
0answers
27 views

Calculate and make a database of prime numbers

I recently created a program for finding a prime number. It's working great and doing it very fast but I was wondering if you can help me make it calculate the prime numbers faster. ...
1
vote
2answers
88 views

Printing all the prime numbers between two bounds

I keep getting a time limit exceeded for this solution to SPOJ Prime1. I need to print all primes within a given interval (with intervals as large as 105, and numbers as large as 109). I've tried ...
5
votes
2answers
56 views

Chen prime finder

I've written a programme to find Chen primes. A Chen prime p is a prime number where (p + 2) is either also a prime number or has two prime factors. I've got it working to the best of my knowledge: ...
7
votes
1answer
89 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
2
votes
1answer
33 views

Project Euler #7 in C: find 10001st prime using something like Sieve of Eratosthenes

I've gotten a solution for Project Euler #7 in C (find the 10,001st prime). I came up with the very simple algorithm myself (from what I can tell it's similar, if not identical, to the Sieve of ...
4
votes
1answer
38 views

Sieve of Eratosthenes in Erlang

I just started learning Erlang. Here is my crack at the Seive, based on (https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf): ...
2
votes
1answer
83 views

Project Euler Q7 - 10001st prime

The problem is (source)... By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? This is my second attempt ...
2
votes
2answers
82 views

Find numbers between 1 and 10000 whose sum of digits are prime

I have the following C code that finds numbers between 1 and 10000 whose sum of digits are prime and save then to a file. ...
2
votes
2answers
42 views

Listing all primes up to a given limit

I started writing Rust by doing a simple program that will print all prime numbers until it reaches the upper bound that is provided through standard input. Here is my code ...
1
vote
2answers
45 views

Getting prime numbers, custom example [closed]

I was tasked this in class today, so the teacher could judge where our skills are. I am not an experienced C++ programmer, and I made a mistake on my sheet, so I came home and wrote this. I saw ...
4
votes
2answers
93 views

Gilbreath's conjecture in Python

I've written some code for testing Gilbreath's conjecture in python (2.x). The conjecture was shown (in the 90s) to be true up to n=1012. My code uses the primesieve module to quickly generate primes ...
3
votes
3answers
76 views

Prime Number Finder in Python

I am creating a simple program that will do three things: add up the prime numbers found within the range set by the user, print out the entire list of prime numbers, and print how many prime numbers ...
5
votes
1answer
81 views

Returns all primes p between m <= p <= n

This is my submission for the Prime Generator on SPOJ and it was accepted. Are there any improvements/changes I can make? Input: The input begins with the number \$t\$ of test cases in a ...
9
votes
2answers
101 views

Number factorization in clojure

I'm just a Clojure noob (started learning yesterday). Here is my helloworld program. It factorizes number into primes. Do you have any comments? How could I make this code cleaner and shorter? Maybe ...
7
votes
1answer
57 views

Prime factorization in F#

In the pursuit of learning F#, I have been working through some Project Euler problems. This is my solution for problem 3: ...
10
votes
3answers
100 views

Project Euler Problem 10. Sum of all primes < 2mil

I'm new to coding so I can't create complex code yet. I do as much as I can with fors and ifs, since while I know a bit about ...
3
votes
2answers
47 views

Very slow Project Euler Q3 (largest prime factor of a large number)

My code returns the correct answer for the example (highest prime of 13195 is 29), but when I test against the number in the question my code basically is too slow for my liking. The prime ...
4
votes
1answer
56 views

Finding the largest prime factor

As many people will undoubtedly recognise, this is a question in a well known series of problems that I won't name ;) It's been a long time since I've written any F# and I'm not sure I've ever come ...
3
votes
2answers
92 views

Generation of Prime Numbers

I have created this prime number generator. I want it to be as fast as possible, but I am wondering if there is a faster way (there must be). ...
8
votes
3answers
3k views

Printing all primes < 1,000,000 to a text file

It takes a long time to execute and the CPU usage for the executable is about 25% while it is executing. Any ideas on how to make this faster? primes.c: ...
4
votes
3answers
171 views

Finding prime numbers in user specified array

I have a program that searches for prime numbers in an array specified by the user. The program starts by asking how big the user wants the array to be, then asks how many threads to split the ...
3
votes
1answer
75 views

Windowed Sieve of Eratosthenes in Java

I wanted to try and use the Sieve of Eratosthenes to find all prime numbers between some arbitrary bounds 1 <= m <= n. The simple implementation of the sieve ...
7
votes
4answers
146 views

Goldbach’s Conjecture in Python

Input Format Input starts with an integer n (1 ≤ n ≤ 100) indicating the number of cases. The following n lines each contain a test case of a single even number x (4 ≤ x ≤ 32000). Output Format For ...
6
votes
1answer
82 views

Prime numbers using wheel factorial

I have written a program to find prime numbers up to a given limit using wheel factorization of 2, 3 and 5. I would like it to work above \$10^{10}\$, but its still pretty slow. What else can I ...
11
votes
2answers
124 views

Quadratic sieve

Here is an implementation I pieced together from various papers on the subject. It took a lot of fiddling to get it to run at all. My ideas for better performance and readability, based on looking ...
3
votes
2answers
54 views

Basic prime summation

I wrote basic Python code for the summation of n primes. It works but I wanted to find out how I could improve it and what shortcuts I missed. ...
4
votes
2answers
492 views

Code Golf Challenge: Calculate Phi (not Pi)

I'm a newbie to C++ (coming from C#) and I decided to complete this Code Golf challenge for fun (though I definitely wouldn't say it's short). Essentially, the challenge was to calculate the ...
-1
votes
1answer
97 views

Calculating the prime numbers between two integers

I've wrote this code to calculate the prime numbers between two integers n and m, and I want to optimise it. ...
2
votes
1answer
33 views

Yet another Sieve of Eratosthenes in Java

I wanted a reusable class for generating a list of primes till some arbitrary (but reasonable) limit. So, I wrote a class Primes that implements the Sieve of ...
2
votes
2answers
65 views

Finding all the prime factors of a number

I want to calculate all the prime factors of a number in the range 2 ≤ N ≤ 107. Here is my function: ...
9
votes
3answers
227 views

Find the Nth number divisible by only 2,3,5, or 7

I recently participated in a small friendly competition and this was one of the questions: A number whose only prime factors are 2, 3, 5 or 7 is called a humble number. The first 20 humble ...
3
votes
2answers
83 views

is_Prime() function on PHP

I tried to make an is_Prime() function in PHP. What do you think about this code? ...
5
votes
2answers
414 views

Slow prime finder

This program runs in about 1.65 seconds on a 1.65GHz dual core processor. I compile it with: gcc -Wall -o ./program ./program.c -lm Are there any optimizations ...
4
votes
3answers
81 views

The Odd-Even Challenge

After posting my first question on here, I got a lot of great feedback. I've decided to try another challenge and write it as cleanly as possible. The rules of Odd-Even consists of the following ...
2
votes
4answers
107 views

Prime number generation algorithm

I'm making a prime number scanning algorithm in Java. It uses the concept of the Sieve of Eratosthenes to efficiently find the prime numbers. It works well and can calculate all the prime numbers ...
6
votes
1answer
81 views

Check sum of all primes under two million

I'm exploring ruby by writing a code that checks the sum of all prime numbers under two million. As I am still in the process of learning ruby, I'm unfamiliar with all the standards and best ...
1
vote
2answers
74 views

Prime factor tree

Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is ...
7
votes
1answer
80 views

Sum of primes in given range in Go

This piece of code calculates the sum of all prime numbers below 1 million. It stood out to me that the Ruby script is around 20% faster. I know that Go should be faster just for being a compiled ...
4
votes
1answer
66 views

Sieve of Eratosthenes Primes Efficiency

I'm fairly new to Java and was trying to make a program that's generates the primes from 2 - 100. I originally had a design of my own making but it was fairly inefficient so I did some research and ...
-2
votes
1answer
43 views

Finding the smallest prime number greater than a user input [closed]

As it says in the title, I am trying to find the smallest prime number greater than my input, 'input.' I have to use the following guidelines when creating my code... You program should implement ...
1
vote
1answer
62 views

Find the kth prime and all the primes below it

It works by finding 2n+1 with n from 1 to k, but not where 2n+1 would be divisible by one of the already known primes. I'd like to know if the program can find every prime, and if so, how it compares ...
5
votes
2answers
148 views

Find the next prime number — flow control of nested `for` loops

This code works perfectly, but it bothers me. Having a labeled, nested for loop, with a true condition, a ...
3
votes
2answers
41 views

Counting finite abelian groups

I wrote this code for this code golfing challenge on the CGPP sister site. It wouldn't really be a competitive entry because I had to write all the functions from scratch. (I didn't even golf anything ...
0
votes
1answer
109 views

Getting prime numbers between a range

I have the following code to get the prime numbers between a range of numbers. Is this the best and fastest method? ...
6
votes
1answer
53 views

Prime generator for SPOJ

I have written code to solve the prime generator problem. I am given an input which contains in the first line the number of test cases, and for each test case, I am given a range and I have to print ...
5
votes
3answers
72 views

Custom Prime Sieve

I've come up with a prime number finder I call the "Progressive Sieve". I wouldn't doubt it if this has already been thought of. Anyway, here is the idea, an implementation in C#, and benchmarks: ...
4
votes
1answer
76 views

Calculating the nth prime number for huge BigIntegers

I wrote this simple class for calculating the nth prime: ...
7
votes
1answer
205 views

A more optimized way of finding prime factors

I've solved Project Euler #3, but solving the same in Hacker Rank which has time constraint of < 4 seconds doesn't work. I've tried using the square root solution for speeding up but it fails. ...
6
votes
2answers
103 views

Finding prime divisors with wheel factorization

I am just starting to learn C++, and I wrote was the following implementation of the trial division algorithm to find the prime factors of a positive integer. I'm hoping the community here can suggest ...
3
votes
0answers
51 views

Sieve32FastV2 - A fast parallel Sieve of Eratosthenes

I’ve created a much cleaner, better designed version to my parallel sieve. I’ve implemented most of EBrown’s micro-optimizations but also revamped the code on my own (that is not in direct response ...