Project Euler Problems for Learn Programming - Solution 3 (Python & Javascript)

in #javascript7 years ago (edited)

Programming

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

Project Euler - Solution 2

Project Euler - Solution 4

Sort:  

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 is 25. Shouldn't that be 5 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 will 169.

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

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 67681.88
ETH 2494.30
USDT 1.00
SBD 2.52