This is my second post. Hi everyone.
ok so i started doing problem number 3 on project euler and meet another obstacle.
Here the problem:
Here my code:The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
When i run the .exe file it do nothing, which mean something is running to infinite and didnt exit the loop. but i did set the loop to stop when prime got larger then max.Code:#include<stdio.h> int main() { long long biggest=0, prime, max=600851475143; for(prime=1; prime<=max; prime++) { if (max%prime==0) { if ( (prime%2!=0) && (prime%3!=0) && (prime%5!=0) && (prime%7!=0) ) { biggest= (biggest>prime) ? biggest : prime; } } } printf ("%d", biggest); return 0; }
Did i do something else wrong? I look for the error in loop for 3 hours now and still couldnt find what went wrong.
Thought process:
_find factor using "max%prime==0"
_find prime factor using "(prime%2!=0) && (prime%3!=0) && (prime%5!=0) && (prime%7!=0)"
_compare biggest with prime. "biggest= (biggest>prime) ? biggest : prime;"
Thanks,