Skip to content

Commit

Permalink
PawanKolhe#2 | Nenad Pantelic | Add third problem solution - largest …
Browse files Browse the repository at this point in the history
…prime factor
  • Loading branch information
NenadPantelic committed Oct 18, 2019
1 parent 7aa0d0f commit 2337fb1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ProjectEulerSolutions/3-largest-prime-factor.c
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>

/*
Find maximum prime factor of number num
*/
int isPrime(int x){

int i,prime = 1;
for (i = 2; i < x && prime; i++){
if (!(x%i)) prime = 0;
}
return prime;
}

int main()
{
long num = 600851475143;
int max_prime = 0;

int i = 3;
while (num != 1){
if (!(num % i) && isPrime(i)){
num /= i;
if (i > max_prime) max_prime = i;
}
i++;

}
printf("%d\n",max_prime);
return 0;
}

0 comments on commit 2337fb1

Please sign in to comment.