-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathsol2.c
More file actions
33 lines (32 loc) · 626 Bytes
/
sol2.c
File metadata and controls
33 lines (32 loc) · 626 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
/**
* \file
* \brief [Problem 3](https://projecteuler.net/problem=3) solution
*
* Problem:
*
* The prime factors of 13195 are 5,7,13 and 29. What is the largest prime
* factor of a given number N? e.g. for 10, largest prime factor = 5. For 17,
* largest prime factor = 17.
*/
#include <stdio.h>
/** Main function */
int main()
{
int n = 0;
scanf("%d", &n);
int prime = 1;
int i = 2;
while (i * i <= n)
{
while (n % i == 0)
{
prime = i;
n /= i;
}
i += 1;
}
if (n > 1)
prime = n;
printf("%d\n", prime);
return 0;
}