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.
12
votes
5answers
969 views
Finding the 10001st prime
I'm solving Project Euler problem 7, which says:
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?
Here's the ...
8
votes
2answers
98 views
Summation of primes for large inputs
I'm doing a problem from Project Euler to find the sum of all primes under two million.
My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it ...
5
votes
2answers
70 views
Project Euler #10 - sum of primes below two million
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
...
3
votes
1answer
74 views
Solving Project Euler problem #60 in C++
I have implemented a solution to Project Euler problem #60. In summary, the problem asks to find the smallest sum of a set of five prime numbers such that the decimal strings of any two numbers in the ...
2
votes
0answers
34 views
Seeking 5 primes such that concatenating any two of them produces another prime
I have a program which solves Project Euler problem 60:
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 ...
3
votes
1answer
105 views
4
votes
2answers
72 views
Calculating sum of primes
This is a little baffling to me as to why the CUDA code runs about twice as slow as the CPU version. The CPU code is commented out above the main. I am just counting all the primes from 0 to (512 * ...
3
votes
2answers
120 views
Function to find two prime numbers that sum up to a given even number
The Goldbach Conjecture asserts that any even number will be the sum of at least two prime numbers. I've created a function to find two prime numbers that add up to the number entered, but would like ...
5
votes
2answers
44 views
BitSet wrapper to act as a sieve abstraction
This is a BitSet wrapper class to act as a Sieve abstraction for a prime calculator. Review for performance and Java/Java 8/Guava best practices.
...
4
votes
2answers
77 views
Find the highest occurring digit in the prime numbers present between L and R (both inclusive)
Given two numbers L and R, find the highest occurring digit in the
prime numbers present between L and R (both inclusive). If multiple
digits have the same highest frequency print the largest ...
2
votes
2answers
70 views
ProjectEuler Problem #3
I'm working on projecteuler.net problems, and I made this for problem #3:
...
6
votes
1answer
61 views
Generating prime candidates
I'd like to generate an infinite list of prime candidates of the form 6k±1, but I'm looking for the fastest possible solution.
Currently I have this:
...
4
votes
1answer
44 views
Pythonic sieve of Erasthotones that saves results to file
I'd like to have some feedback on this sieve of erasthotones that I've wrote. It outputs all prime numbers up to n correctly (I've tested with the first 10k prime ...
3
votes
2answers
135 views
Euler 357 solution efficiency
I have a Ruby program which should solve the following problem:
Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that
for every divisor d of 30, d+30/d is prime.
Find the sum ...
11
votes
1answer
108 views
Compile-time sieve of Eratosthenes
There are many instances of prime number sieve implementation both here and other places on the web, but I wanted something a little different. In particular, I wanted to create a static array of the ...
5
votes
4answers
789 views
Efficient Sum of Primes
I wrote this simple implementation of the sum of primes for the code eval
Challenge Description:
Write a program which determines the sum of the first 1000 prime numbers.
I would like to ...
4
votes
7answers
1k views
Primes Without 1's
Requirement primes numbers which do not have digit 1 in it.
Input
The first line contains T, the number of test cases. Followed by T
lines each contain two numbers M and N
Output
...
2
votes
3answers
80 views
HackersEarth - Reverse primes
Generate as many distinct primes P such that reverse (P) is also prime
and is not equal to P.
Output: Print per line one integer( ≤ 10^15 ). Don't print more than
10^6 integers in all.
...
4
votes
1answer
122 views
Finding all prime factors of a number
I have a function that is able to return the factors of a number that are prime.
For example: The prime factors of 13195 are 5, 7, 13 and 29.
The function works great, and I was even able to improve ...
2
votes
2answers
86 views
Optimized ulong prime test using 6k+/-1 in parallel threads with C#
For primality testing of 64 bit ulong, I have optimized a very fast trial-by-division test using possible factors of the form 6k+/-1. For input numbers less than ...
0
votes
3answers
112 views
Sum of maximum primes as another prime below a million
This is a project Euler Problem #50. Here is my solution with the problem.
...
0
votes
1answer
47 views
Sieve32, a simple 32 bit sieve returning IEnumerable<uint> using C#
What a difference 1 bit makes! This very fast, simple sieve of Eratosthenes quickly finds 32 bit primes. It uses a memory efficient BitArray for odd numbers – but ...
10
votes
2answers
147 views
Sieve31, my sieve of Eratosthenes returning IEnumerable<int>
This very fast, simple sieve quickly finds 31 bit primes. It uses a memory efficient BitArray for odd numbers.
How a 32 bit ...
5
votes
3answers
151 views
Wheel based unbounded sieve of Eratosthenes in Python
Answering this SO question recently, I've developed the following code (based on a well-known Active Code recipe, as discussed here):
...
1
vote
1answer
59 views
Sum of primes between two number from optimized Sieve of Eratosthenes
Here is the code that I wrote to give me sum of prime numbers between n and m:
...
3
votes
1answer
94 views
Project Euler #10 and #12 in Java - Prime Numbers
I am dealing with a huge time taking with primes. I hope you know they are pretty random and that's why create many problem. Both are using the same logic/methods.
...
1
vote
1answer
54 views
A non-static Sieve of Eratosthenes class, version 1
Over the years I’ve seen many C# sieves and despite their varying internals all that I have seen invariably are a static method that returns a List<int>, ...
2
votes
2answers
55 views
Effecient Use Sieve of Eratosthenes algorithm
Given this as a the Problem Statement
Given two numbers, find the sum of prime numbers between them, both
inclusive.
Input:
The first line contains the number of test cases T. Each ...
5
votes
3answers
144 views
Finding the Nth prime
I'm going through some of the problems over on exercism and we were asked to write a program that finds the nth prime. I know Ruby has a Prime class that handles that but the exercise doesn't allow us ...
6
votes
4answers
566 views
Euler #3 largest prime factor
Problem Statement
This problem is a programming version of Problem 3 from projecteuler.net
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of a given number ...
7
votes
1answer
70 views
5
votes
4answers
371 views
Project Euler 50 in Python
Project Euler, problem #50:
The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive
primes that adds to a ...
4
votes
2answers
54 views
4
votes
2answers
74 views
Prime factorization in Haskell
I am a Haskell beginner. Here is my function to find prime factors of a number
...
3
votes
1answer
64 views
Testing Fibonacci conjecture
The sequence of Fibonacci numbers is defined as F1 = 1, Fn = Fn−2 +
Fn−1. It has been conjectured that for any Fibonacci number F, F2 + 41
is composite.
... [T]ask is to either prove the ...
3
votes
1answer
73 views
Project Euler #10 in Ruby - summation of primes
I'd like to have some feedback as to the performances of the algorithm.
...
0
votes
0answers
29 views
Sieve of Eratosthenes in Clojure
I am mainly interested in how to make the sieve lazy so that it will receive something like (iterate inc 2) and generate an infinite sequence of primes, but any ...
2
votes
0answers
68 views
1
vote
1answer
143 views
Consecutive Primes challenge at CodeEval.com
I am working through a new challenge on CodeEval.com and I think I am getting a correct result but I can't get through their grader. I am not exactly sure where error is. I didn't post this on stack ...
5
votes
2answers
508 views
Printing the n'th prime numbers
This is an online problem. The challenge is to print the kth prime number, for each k given in the input (1 ≤ k ≤ 15000). The first line of input indicates the number of inputs on the subsequent N ...
3
votes
1answer
129 views
Project Euler #10 in Ruby. Three ways to sum primes below 2 million
Question:
Add all prime numbers smaller than 2,000,000.
The first method is done by deriving own is_prime? method:
...
7
votes
3answers
746 views
4
votes
3answers
164 views
Sieve of Eratosthenes in C#
Just because I've never written a real Sieve of Eratosthenes, I decided I should probably write one just to make sure I know what it is. I'd like (constructive) criticism on best practices, potential ...
3
votes
1answer
56 views
Factors sieve optimization
I have written a more powerful version of the sieve of Eratosthenes: this sieve returns the number of factors of all the numbers below the limit. Sadly the running ...
6
votes
2answers
385 views
Sum the exponents of the prime factors of a number
My goal is to find the sum of the exponents of the prime factors of an integer.
I wrote the code below with the complexities specified here (I am not 100% sure of the complexities though):
Runtime ...
4
votes
1answer
110 views
Prime number calculator using Sieve of Eratosthenes
I've been writing this prime number calculator, and I've gotten it pretty quick in comparison to most I've seen knocking about. This one uses the Sieve of Eratosthenes approach, and I've optimised the ...
4
votes
3answers
72 views
Prime factorization of an integer
I have just started learning functional programming (Haskell) for fun after using imperative languages my whole life. I am looking for quick and simple tips from pros on how the particular code I just ...
2
votes
2answers
75 views
Prime factors of a number in C
The following is code on "prime factors of a number". Any suggestions to optimize the code? It runs for a pretty long time for inputs like 35068499. I also want the code to take 10 digit numbers as ...
6
votes
3answers
125 views
Sieve of Sundaram for Project Euler 7
This is a sequel to my previous question: Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R
I am trying to implement the Sieve of Sundaram in various languages to ...
3
votes
2answers
63 views
Factorisation code running slow
I'm still in the process of learning Python and am doing some of the Project Euler problems.
I have made a factorisation algorithm that works; however, it runs really slowly, and I'm not too ...