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)

4
votes
2answers
52 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
66 views

ProjectEuler Problem #3

I'm working on projecteuler.net problems, and I made this for problem #3: ...
6
votes
1answer
42 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
42 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
102 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
103 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
761 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
73 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
96 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
80 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
108 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
42 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 ...
6
votes
0answers
69 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
140 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
56 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
81 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. ...
0
votes
1answer
47 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
50 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
117 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
552 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
66 views

Fermat Factorization

Please review my implementation of Fermat's Factorization. ...
5
votes
4answers
330 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
52 views

Memoized Prime Generator

Here is my code: ...
4
votes
2answers
67 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
69 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
28 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
61 views

Prime numbers generator in Clojure

Any suggestions on improvement are welcome. ...
1
vote
1answer
130 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
334 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
100 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
609 views

Checking if a number is prime

Is there a better way to check if a number is a prime? ...
4
votes
3answers
157 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
55 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
366 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
105 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
73 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
124 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
60 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 ...
3
votes
3answers
120 views
2
votes
2answers
81 views

Sieve of Eratosthenes JavaScript implementation - performance very slow over a certain number

I've been playing around with the code challenges on projecteuler.net. A few of them involve prime numbers, so I've created a function to find them based on the sieve of Eratosthenes. It works fine, ...
1
vote
1answer
43 views

Naive primality test and summation

I am starting to learn Haskell, so I coded a naive solution to the primality test and summation of primes (Project Euler Problem 10: sum of all primes under 2 million) . As I have an imperative ...
1
vote
1answer
92 views

English phrases, prime numbers, pseudo random data and encryption source code check

This code uses a DCG and pairs phrases into near-English sentences. If anyone is familiar with Prolog, I'm wondering how I can use the code as an encryption method by hiding data and replacing it ...
5
votes
1answer
680 views

Listing the first 100 prime numbers

I thought of this implementation, and I want to get feedback from you.. what design would you use for printing first 100 prime numbers? I used the fact that, if the number is not divisible by any ...
3
votes
3answers
327 views

Project Euler 35: Circular primes below 1 million

I'm doing another Project Euler problem, number 35, and I need help improving my code speed: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
4
votes
6answers
2k views

Project Euler #10 — Summation of primes takes forever

I have resolved the Problem presented in Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. But this code takes too ...
6
votes
1answer
108 views

Making prime (sieve) code faster and able to run on big numbers

For an input triple (a, b, c), the task is to count the number of integers in the inclusive range [a, b] which have c distinct prime factors. This entails factoring each of the numbers in the range ...
5
votes
1answer
336 views

Printing prime numbers in Assembly

I am learning to code in the Assembly language for the x86 architecture. I currently know of a few registers and certain arithmetic operations like add, sub, inc, dec, mov and to check for ...