44 lines
793 B
C
44 lines
793 B
C
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
static int
|
|
isPrime(long number)
|
|
{
|
|
if (number <= 1)
|
|
return 0;
|
|
for (long i = 2; i * i <= number; i++)
|
|
if (number % i == 0)
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const long number = 600851475143;
|
|
long remainder = number;
|
|
long largestPrimeFactor = 1;
|
|
float percentComplete = 0.00;
|
|
|
|
while (remainder % 2 == 0)
|
|
remainder /= 2;
|
|
while (remainder % 3 == 0)
|
|
remainder /= 3;
|
|
while (remainder % 5 == 0)
|
|
remainder /= 5;
|
|
|
|
// I love types
|
|
long sqrtOfRemainder = (long)sqrt((double)remainder);
|
|
|
|
for (long i = 7; i < sqrtOfRemainder; i++)
|
|
{
|
|
if (number % i == 0 && isPrime(i))
|
|
{
|
|
printf("Prime factor found: %ld\n", i);
|
|
largestPrimeFactor = i;
|
|
}
|
|
}
|
|
|
|
printf("The largest prime factor of %ld is %ld\n", number, largestPrimeFactor);
|
|
}
|