Project Euler Problems for Learn Programming - Solution 3 (Python & Javascript)
Hey SteemIt community. Did you heard about Project Euler? If you don't know please review this website: 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 (Python)
number = 600851475143
i = 2
while i * i < number:
while number % i ==0:
number = number / i
i = i + 1
print(number)
Solution (Javascript)
var number = 600851475143;
var i = 2;
while (i * i < number) {
while (number % i == 0) {
number = number / i;
}
i = i + 1;
}
console.log(number)
Result: 6857
This post recieved an upvote from minnowpond. If you would like to recieve upvotes from minnowpond on all your posts, simply FOLLOW @minnowpond Please consider upvoting this comment as this project is supported only by your upvotes!
According to this solution, the prime factor of
25
is25
. Shouldn't that be5
instead?You're right. I forgot notice that if largest prime factor's square equal to number, solution is invalid. Let's suppose that our number is
169
then result will169
.Congratulations @scaevola! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
You published a post every day of the week
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP