I'm playing through project Euler in my spare time, and it's come to the point where I need to do some refactoring. I've implemented Miller-Rabin, as well as a few sieves. I've heard before that sieves are actually faster for small-ish numbers, as in under a few million. Does anybody have any information on this? Google wasn't very helpf...
Hey, I'm trying to generate a list of primes below 1 billion. I'm trying this, but this kind of structure is pretty shitty. Any suggestions?
a <- 1:1000000000
d<- 0
b <- for (i in a) {for (j in 1:i) {if (i %% j !=0) {d <- c(d,i)}}}
...
I've been interested in the problem of finding a better prime number recognizer for years. I realize this is a huge area of academic research and study - my interest in this is really just for fun. Here was my first attempt at a possible solution, in C (below).
My question is, can you suggest an improvement (without citing some other...
Okay so I"m writing a program (in C++) that is supposed to take a number, go through it, find out if it's factors are prime, if so add that to a sum, and then output the sum of all of the imputed number's prime factors.
My program successfully seems to do this however it has 2 problems,
1) The number I am supposed to test to see the ...
First of all - I checked a lot in this forum and I haven't found something fast enough.
I try to make a function that returns me the prime numbers in a specified range.
For example I did this function (in C#) using the sieve of Eratosthenes. I tried also Atkin's sieve but the Eratosthenes one runs faster (in my implementation):
public s...
Find largest number with all contiguous triples being unique primes
If the digits of the answer are
pqrstu...xyz
then pqr, qrs, rst ... etc are all unique primes.
As expected, extra points for speed, conciseness, and other good things.
I can run Python/C/C++/Java on my comp and will try to update the answers with the running time of...
Hi,
I'm solving some classic problems in Haskell to develop my functional
skills and I have a problem to implement an optimization suggested at http://programmingpraxis.com/2009/02/19/sieve-of-eratosthenes/
I have three "solutions" to this problem and the third one is too slow
compared to the second solution. Can someone suggest some...
Hy there i a beginner in java started 3 weeks ago, im having some problems with this code.
in the main method i have an array containing 10 elements.
i've already made several methods to like
public static void println(int[] array) ------ to print and array
public static boolean isPrime(int el) ----------- prime test. returns tru...
I have implemented "sieve of eratosthenes" to solve an SPOJ problem. Though the output is fine, my submission exceeds the time limit. How can I reduce the run time?
int main()
{
vector<int> prime_list;
prime_list.push_back(2);
vector<int>::iterator c;
bool flag=true;
unsigned int m,n;
for(int i=3; i<=32000;i+=2)
{
flag...
I am aware the following isn't the fastest way of generating a list of primes however I posed myself the problem and before googling wrote the following program. It works fine for numbers < ~ 44,000 but then gives a segmentation fault when ran on my 2Ghz Core 2 Duo Macbook. I am not really interested in alternative methods at the moment ...
When I run this code, even for just counting to the 10th prime number (instead of 1000) I get a skewed/jacked output--all "not prime" titles for my is_composite variable, my test_num is giving me prime and composite numbers, and my prime_count is off
Some of the answers that developers have shared use functions and the math import--that...
Just to clarify, this is not a homework problem :)
I wanted to find primes for a math application I am building & came across Sieve of Eratosthenes approach.
I have written an implementation of it in Python. But it's terribly slow. For say, if I want to find all primes less than 2 million. It takes > 20 mins. (I stopped it at this poi...
I am trying to implement either the Fermat, Miller-Rabin, or AKS algorithm in Java using the BigInteger class.
I think I have the Fermat test implemented except that the BigInteger class doesn't allow taking BigIntegers to the power of BigIntegers (one can only take BigIntegers to the power of primitive ints). Is there a way around this...
Who wants to help me with my homework?
I'm try to implement Fermat's primality test in Java using BigIntegers. My implementation is as follows, but unfortunately it doesn't work. Any ideas?
public static boolean checkPrime(BigInteger n, int maxIterations)
{
if (n.equals(BigInteger.ONE))
return false;
BigInteger a;
...
Hi,
I want to print all prime numbers that are 2-digits long. Here is my code:
for(int input = 11; input <= 99; input += 2){
for(int x = 2; x < (int)Math.sqrt(input) + 1; x++){
if(input%x != 0){
System.out.println(input);
break;
}else{
break;
...