p03.cpp
535 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Largest prime factor
Problem 3
Published on Friday, 2nd November 2001, 12:00 pm; Solved by 256800
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
By: dbk
*/
#include <stdio.h>
#define CALCULAR 600851475143
#define MAX 1000000
int main(int argc, char const *argv[])
{
long res = 0;
long valor = CALCULAR;
for (int i = 2; i < MAX; i++)
{
while ( valor % i == 0)
{
valor /= i;
res = i;
}
}
printf("Mayor factor primo: %ld\n", res);
return 0;
}