Primes or prime numbers are numbers which are divisible only by themselves and one: 2, 3, 5, 7, 11, ... They are commonly used in encryption and hashing algorithms

learn more… | top users | synonyms (1)

0
votes
0answers
20 views

Sum of Primes between two number from Optimized Sieve of Eratosthenes

Here is the code that i wrote that is working for me to give me sum of prime numbers between n and m. ...
3
votes
1answer
65 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
36 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
41 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 ...
0
votes
0answers
27 views

Finding prime numbers in the range (m,n) [closed]

Problem : Find all prime numbers in the range (m,n). Input : No. of Test cases, m, n. Eg. 2 1 10 3 5 Output : Primes (m,n) Eg. 2 3 5 7 3 5 Here is my code : ...
5
votes
3answers
98 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
520 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
57 views

Fermat Factorization

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

Memoized Prime Generator

Here is my code: ...
4
votes
2answers
50 views

Prime factorization in Haskell

I am a Haskell beginner. Here is my function to find prime factors of a number ...
3
votes
1answer
61 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
66 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
22 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
42 views

Prime numbers generator in Clojure

Any suggestions on improvement are welcome. ...
1
vote
1answer
116 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
237 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
64 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
511 views

Checking if a number is prime

Is there a better way to check if a number is a prime? ...
3
votes
3answers
131 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
53 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
338 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
88 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
69 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
69 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
114 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
56 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
118 views
2
votes
2answers
72 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
42 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
79 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
377 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
224 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
7answers
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
93 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
267 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 ...
10
votes
3answers
795 views

Sum of First N Primes

Task: Print sum of first 1000 primes. ...
2
votes
2answers
1k views

Prime numbers less than a given number N

So, I began this challenge on CodeEval, which asks to print out the number of prime numbers less than any given integer N, where 0 < N < 4,294,967,295, ideally in O(N log N) time. I came up ...
5
votes
5answers
590 views

Improving isPrime method

I've been doing some programming challenges and problems lately and it seems like many involve primes. I concluded that I would benefit from optimizing how I'm checking for them. Currently I'm using ...
4
votes
3answers
147 views

Project Euler Problem #10

I've read other solutions about solving the 10th problem for Project Euler (finding the sum of all prime numbers under 2,000,000) but I wanted to try it on my own using the Sieve of Eratosthenes ...
1
vote
2answers
111 views

Haskell monads: sum of primes

They say you cannot get out of the monad, but I need to use the result (at least for assertions / unit tests). But print how does it do it? Otherwise, I worked ...
2
votes
1answer
63 views

Project Euler #12 in Swift - Highly divisible triangular number

I just finished Project Euler #12 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The sequence of triangle ...
2
votes
1answer
250 views

A prime number sieve using recursion

Out of curiosity, I built a recursive Sieve of Eratosthenes in Python and I was wondering how it could be improved for efficiency and how it can improved to be aligned with python best practices. ...
5
votes
1answer
84 views

Project Euler #10 in Swift - Summation of primes

I just finished Project Euler #10 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. I hope I learned some from ...
1
vote
1answer
40 views

Project Euler #3 in Haskell

Project Euler #3 asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I've written a general solution for any number: ...
12
votes
6answers
1k views

Prime Number Checker

This is my prime number checker in C++. I know that calculating the square root of a number can be very costly, so I don't do it unless the number is larger than 10k, where we would have to check ...
6
votes
2answers
135 views

Project Euler #7 - 10001st prime

I just finished Project Euler #7 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. By listing the first six ...
3
votes
2answers
123 views

Prime Number Sequence generator

I have just started using Python, and I am attempting to make a prime number sequence generator, where it will print the a specified amount prime numbers in terminal. I have other versions of this ...
1
vote
1answer
71 views

Prime Number Sieve Optimization

I've written my own prime number sieve in JavaScript. It loops through numbers 1-100 and puts them in one of two arrays, depending on if it is composite or prime. I was wondering if there are any ...
5
votes
1answer
133 views

Isprime Android app with kivy

I thought that developing an app in Python should be easier than learning Java. I finally got my isprime app to work but it looks ugly. When I write GUI code I always find myself typing in very long ...