Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Greatest program to find the largest prime factor

Name: Anonymous 2016-02-21 1:30

I was asked this question by project euler -
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

I think I came with the greatest solution in the world.
I challenge anyone to do better than this.
It's 10 lines of code and finds the solution in less than 10 milliseconds.

Seriously, you can try as much as you want, but this solution is already the best in the world.

#include <stdio.h>
int main(void)
{
int i = 2;
long n = 600851475143;
for (; n > 1; i++)
for (; n % i == 0; n /= i)
printf("%d\n", i);
return 0;
}

Name: Anonymous 2016-02-24 16:03

I can understand what it does, but I can't understand how it yields in the prime factors of the input number.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List