Project Euler Problem 3:
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
Solution:The key point is how to verify a number is a prime or not. One probable way is to divide it by every odd number which is less than its square root. For instance: we try to find the largest prime factor of 63:
1st step: divide it by 3, result is 21;
2nd step: divide 21 by 3, result is 7;
3rd step: since 7 is not divisible by 3 so move to the next odd number,
i.e.$3+2=5$. But 5 is bigger than $\sqrt7$, so the result is 7.
The largest prime factor of 600851475143 is 6857.
R Code
Python Code
没有评论:
发表评论