The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Quick Powershell Solution:
- $num = 600851475143
- $max_prime = 1
- $end1 = 0
- while($end1 -eq 0)
- {
- $factor = 2
- $end2 = 0
- while($end2 -eq 0)
- {
- if($num%$factor -eq 0)
- {
- if($max_prime -lt $factor)
- {
- $max_prime = $factor
- }
- $num = $num/$factor
- $end2 = 1
- }
- $factor = $factor+1
- }
- if($num -eq 1)
- {
- $end1 = 1
- }
- }
- echo $max_prime
Note: The solution may not be the optimized one… just a quick hack… I’ll revisit later for optimization if time permits… :-)
No comments:
Post a Comment