Primes or prime numbers are numbers which are divisible only by themselves and one: 2, 3, 5, 7, 11, ...

learn more… | top users | synonyms

5
votes
1answer
31 views

Project Euler #41 - pandigital prime

I've written a solution to Euler 41: We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is ...
7
votes
2answers
289 views

Finding prime factors of a number?

Okay, so just having a little fun I thought I'd see if I could write an algorithm to find all of the prime factors of a number. The solution I came up with is as follows: class Program { static ...
6
votes
1answer
49 views

Number of prime numbers between 1 and n in javascript

I came up with following solution to find the number of prime numbers from 1 to n. Wondering if there is a more optimal way. var max = 10; var compositeNumbers = {}; mainLoop: for (var i=2; i<= ...
3
votes
4answers
86 views

Relative prime numbers

Two integers a and b are relatively prime if and only if there are no integers: x > 1, y > 0, z > 0 such that a = xy and b = xz. I wrote a program that determines how many positive integers less ...
3
votes
3answers
171 views

Smallest prime factor of a large number (using BigInteger)

I'm working on a Project Euler problem and am trying to get the smallest prime factor of a BigInteger: private static BigInteger smallestPrimeFactor( BigInteger n ){ for( BigInteger i = new ...
7
votes
2answers
194 views

Checking for circular primes - Project Euler Problem 35

I have been trying to solve Project Euler problem number 35. The problem is to find: How many circular primes are there below one million? A circular prime is a prime where all the rotations of ...
2
votes
2answers
57 views

Find next consecutive prime and find nth prime

Code review for best practices, optimizations, bug detection etc. Also please verify my complexity as mentioned within the function comments. /** * Util class with 2 functions, * 1. find the next ...
11
votes
4answers
282 views

Suggestions for improvement on Project Euler #7

Here is a solution for Project Euler Problem #7. 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 10,001st prime number? I've ...
2
votes
3answers
108 views

Project Euler #12 in C++ - highly divisible triangular number

Project Euler Problem 12 asks (paraphrased): The nth triangular number Tn = 1 + 2 + … + n. T7 = 28 has 6 divisors (1, 2, 4, 7, 14, 28). What is the first Tn to have over 500 divisors? After ...
5
votes
3answers
395 views

Summation of primes takes forever

Project Euler Problem 10 asks: "What is the sum of all prime numbers below 2 million?" How do I speed up my code? It's taking forever and I have never gotten the answer. However, I am sure that my ...
0
votes
1answer
21 views

Caml light and finding the prime factors

I wrote the following Caml light code to find prime factors of a number (part of an early Project Euler question). Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. ...
3
votes
3answers
213 views

Determining whether or not a number is prime

I wrote this code in Java without using any methods, just by using simple for loop and if statements. When we input a number, it checks whether it's a prime or not. If it's a prime, then it prints ...
3
votes
3answers
180 views

How Pythonic is my Project Euler #5? (LCM of [1, 2, …, 20])

I have implemented a solution to Project Euler problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive ...
0
votes
0answers
81 views

Optimizing my Quadratic Sieve, with advice on style?

I'm still new to Haskell, and I'd like others' opinions on optimizing my basic quadratic sieve, in addition to feedback on the code's clarity and functional style. The qs function currently runs out ...
2
votes
5answers
104 views

Is there a shorter way to print out prime numbers from an array given a max number in ruby

Is there a shorter or maybe a cleaner way of doing: Q: Using your is_prime? method, write a new method, primes that takes a (non-negative, integer) number max and returns an array of all prime ...
0
votes
1answer
58 views

Review my prime factorization function. Is it complete?

This is a function designed to return all the prime factors of a given number, in sorted order from least to greatest, in a list. It relies on another function that checks if a given number is prime. ...
3
votes
1answer
65 views

Is a Recursive-Iterative Method Better than a Purely Iterative Method to find out if a number is prime?

I made this program in C that tests if a number is prime. I'm as yet unfamiliar with Algorithm complexity and all that Big O stuff, so I'm unsure if my approach, which is a combination of iteration ...
2
votes
1answer
40 views

Any problems with this prime checker script?

I have just made what seems to me to be the first reliable prime-checking program that works. However, I am not sure if it is completely reliable, or if there are problems. It relies on list-making ...
2
votes
3answers
407 views

Project Euler Problem 7: Find 10001st prime number

I was able to complete the problem, but I would like to improve my code and make it more idiomatic. Here is the challenge description: Problem 7 - 10001st prime By listing the first six ...
3
votes
1answer
121 views

Prime number dictionary

I attempted to write a read-only dictionary, containing primes: #inspired by http://ceasarjames.wordpress.com/2011/07/10/the-quadratic-sieve/ class PrimeDict(dict): def __init__(self): ...
3
votes
2answers
87 views

Attempting to efficiently compute the largest prime factor

As per the help, here's what I'm looking for from this post: best practice and practical advice about (what I think is describable as) buffering the output of a function. So I'm working on the third ...
5
votes
2answers
300 views

Improving remake of factoring/prime factorization calculator

Background info on factoring and prime factorization. I've remade this program from my first attempt, and I'm sure it can still be improved. My questions: These calculations should only be done ...
0
votes
2answers
487 views

Problem in calculating prime numbers in python [closed]

I'm a noob in programming. I was asked to code a program that can calculate prime numbers. So i coded as provided below. But it prints all the Odd Numbers instead of Prime Numbers. I think the Value ...
5
votes
2answers
158 views

Sieve of Erastosthenes in Java

Here you can find my implementation of sieve of eratosthenes in Java. /** * Return an array of prime numbers up to upperLimit * using sieve of Erastosthenes. * @param upperLimit * @return array ...
4
votes
1answer
90 views

Questions about opinions on prime number generator

What do you consider the readability of this program? Do you think it's easy to understand what the variables and functions do just by reading their names? Would you prefer more, less, or this amount ...
1
vote
1answer
144 views

Clojure code for finding prime numbers

This is my Clojure code for finding prime numbers. Note: this is an advanced version which starts eliminating from i*i with step i, instead of filtering all list against mod i == 0 (Sieve of ...
4
votes
1answer
130 views

Prime test - style and correct idiom review please

Below is some code I've created to generate and use a list of prime numbers. This is some of the first common lisp code I've written, and I'd be grateful for any comments regarding style and its use ...
4
votes
4answers
372 views

better code for generating primes

After considerable effort, I've come up with the following code to generate a list of primes of given length. I would be very interested to see how an experienced coder would modify my code to make it ...
3
votes
2answers
207 views

Object-oriented design of list of primes

Is there a better way to implement this class, or does it not constitute implementation in the first place? This is one of my first few tries at OOP. Any suggestions will be much appreciated. ...
0
votes
1answer
99 views

Sphere Online Judge, Problem 2: Prime Number Generator

I am trying to solve this problem on Sphere Online Judge. I keep getting a timeout error. Any comments or suggestions are welcome and appreciated. package info.danforbes.sphere; import ...
1
vote
3answers
233 views

Reducing time limit for prime number program

I have to create a program in which t sets of m and n will be given by the user. For each set, we have to generate all prime numbers between m and n. This code is successfully executed with the ...
1
vote
1answer
76 views

First use of std::map in factors and prime factorization program

This is from an older question of mine that I decided to revisit: Simple and efficient code for finding factors and prime factorization? In that question, someone suggested I use an std::map to hold ...
4
votes
1answer
162 views

Prime Numbers Store

Problem definition: Lets say we need to create a store for selling prime numbers. Users enter the store and ask to buy a number. If the number asked is a prime number, 1.1. then it's either ...
2
votes
1answer
222 views

Greatest prime number smaller than N where N can be as large as 10^18?

This is code for finding largest prime number smaller than N where N can be as large as 10^18. But it takes 1 minute for 10^18 . I need to pass it in 2-3 sec. What changes should I make to pass it. ...
7
votes
1answer
482 views

Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?

Project Euler problem 407: If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1. The largest value of a such that a2 mod 6 = a is 4. Let's call M(n) the largest value of a < n ...
1
vote
3answers
187 views

Project Euler problem 37: truncatable primes

I am working on Project Euler problem 37 and I have the following program: #!/usr/bin/ruby -w require 'prime' h=11 y=0 x=0 while x < 11 if h.prime? == true boo = true f=0 ...
2
votes
1answer
100 views

Help me speed up this Java code. Deals with HUGE list of ints

Below is the code I have written. I started yesterday with prime numbers and playing around with them. What the code does it determines the "prime gap" between primes numbers, prints them, then finds ...
3
votes
1answer
85 views

Quadratic Primes

This is one of the slightly trickier Project Euler Questions I have seen (Question 27) Considering quadratics of the form: n² + an + b, where |a| < 1000 and |b| < 1000 where |n| is the ...
4
votes
4answers
463 views

Sum of primes less than 2,000,000

I have been attempting the questions at Project Euler and I am trying to find the sum of Primes under two million (question 10) The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the ...
5
votes
1answer
219 views

Calculating prime factors in MIPS assembly

The goal of this was to be able to enter any number and print out the prime factors of that number. Are there any shorter ways of writing this code? I'm not very familiar with low-level syntax and was ...
4
votes
2answers
136 views

Prime sieve: improve efficiency while keeping it reasonably simple?

public static void listPrimesThree(int maxNum){ long startTime = System.currentTimeMillis(); boolean[] booleanArray = new boolean[maxNum+1]; int root = (int)Math.sqrt(maxNum); for (int m = 2; m ...
1
vote
1answer
94 views

Optimizing code for project-euler p#23

I'm working on project euler's problem #23, wich is Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers So I came up with this algorithm. Find ...
6
votes
1answer
203 views

Is this the most efficient way to see if the number is prime?

my question is in the title really...is this the most efficiant way to find if a number is prime? public boolean primes(int num){ for(int i = 2; i < num; i++){ if(num % i == 0){ ...
0
votes
2answers
1k views

Prime Number Generator algorithm optimization

I've implemented a simple program that finds all prime numbers between two integer inputs using Sieve of Eratosthenes, but the online judge is still complaining that the time limit is exceeding. Maybe ...
0
votes
2answers
328 views

Miller-Rabin Prime test (Speed is the main goal)

The code below is for testing Primes. testPrime(100000); testPrime(1000000); testPrime(10000000); testPrime(100000000); Now my goal is to make the code super fast at finding prime number, min-max, ...
0
votes
1answer
94 views

Project Euler 10: Summation of primes in Go

Here is my first try at googles Go language, trying to solve Eulers Problem 10: http://projecteuler.net/problem=10 Any suggestions on the style and usage (best practice) of Go? One more thing, ...
-1
votes
1answer
161 views

How to apply Sieve of Eratosthenes test into my code [closed]

I have this code that tests prime numbers and I'm trying to make it fast as possible. I know a way but I just can't find how to execute it in to my code. Does any one know how to input in to the code ...
3
votes
1answer
675 views

Simple and efficient code for finding factors and prime factorization?

I've modified this program many times, but I want to know if this is a good way to perform this task. My first algorithm for finding the factors of a number was pretty slow and horrible (started at ...
1
vote
3answers
184 views

Primes Tester for speed performance

I was given a homework assignment in Java to create classes that find Prime number and etc (you will see in code better). My code: class Primes { public static boolean IsPrime(long num) { ...
2
votes
3answers
192 views

Project Euler Problem #3 - largest prime factor

I have began doing the problems found on Project Euler and have just solved problem 3. However, I feel as if my code is very long and too brute-force. I was hoping somebody could give it a look and ...