> The prime factors of 13195 are 5, 7, 13 and 29. >What is the largest prime factor of the number 600851475143 ?
Can anyone help me on this one? I'm learning C# and having a hard time grasping the logic here. I'm supposed to calculate prime numbers first right? But I just can't find a good formula for that
Chase Taylor
This isn't homework or anything, just something I'm taking up in my spare time.
Andrew Evans
Watch Numberphile on YouTube for this kind of problems solved fun way. James Grime is my hero.
Cameron Jackson
make an array on n numbers from 2 to the numer you want - 1,then if a number divides n then every a*k in the array is turned into a zero, then go to the next non-zero number and repeat the process, if you want instead of the array being from 1 to n make it from 1 to sqrt(n) after the process the array has the factors of the number.
Xavier Rodriguez
>implying Sup Forums doesn't know about project Euler
Justin Butler
naive algorithm for prime factorization would be (sorry don't know C#) def factorize(num): primes = list() while num != 1: for i in range(2, int(num+1)): if num % i == 0: primes.append(i) num /= i break return primes
Here is the code btw void factors(long n) { int j; long sieve = sqrt(n) +1; int c = 0; int *arr = new int[sieve];
for (int i = 0; i < sieve; i++) arr[i] = i + 2;
for (int i = 0; i < sieve; i++) { if (arr[i] != 0) { if (n % arr[i] == 0) { c++; j = arr[i]+i; while (j < sieve) { arr[j] = 0; j+=arr[i]; } } else arr[i] = 0; } }
for (int i = 0; i < sieve; i++) { if (arr[i] != 0) { cout
Carson Murphy
Neat
Brandon Torres
>just make an array with 600 billion elements
Zachary Johnson
Use a sieve and run it for a week :^)
Kevin Hughes
>he can't make an array of 77459 elements
Lincoln Cook
Man your solution runs way quicker, I had a bad approach doing something akin to fin the prime numbers.
Jason Morales
you don't need to verify until n. Remember there are no prime factors higher than sqrt(n).
Jaxon Harris
>the modulo operator its that simple.
Connor Clark
Fundamental theorem of arithmetic is your friend.
Joshua Roberts
I'll take a look, thanks.
Robert Cruz
What if n is prime?
Jace Sanchez
Project Euler thread?
Pic related is me, I've been doing them on and off since the begining of summer or so.
I like using the earlier problems as an introduction to new languages, it's like the mathematical equivalent of Hello world.
Asher Nguyen
You can do from 2 to N/2 - 1, because there will be no prime factors from N/2 to N. Depending on the other factors involved, you could dynamically shrink the upper bound of the factor check.
Ryder Thomas
Some sieve of Erathostenes -even an imperfect one- will do.