* fix(guide) add stubs and correct file path misspellings and pr… (#36528) * fix: corrected file path to match curriculum * fix: renamed to newer challenge name * fix: added solutions to articles from challenge files * fix: added missing .english to file name * fix: added missing title to guide article * fix: correct solution for guide article * fix: replaced stub with hint * fix: added space in Hint headers * fix: added solution to guide article * fix: added solution to guide article * test: replaced stub with hint and solution * fix: add Problem number: to title * fix: changed generatorexponential to correct name * fix: renamed knight's tour to knights-tour * fix: updated guide article
994 B
994 B
title
title |
---|
Problem 3: Largest prime factor |
Problem 3: Largest prime factor
Problem Explanation
- To find the largest prime factor of a number, we start from the smallest prime factor 2 and divide the number with it.
- If the remainder is 0 that means the number is divisible by that prime number, we keep dividing the number by same prime number until that number is no more divisible by that prime number.
- After that, we incrememnt the prime factor by 1 and repeat this process till the number becomes 1.
Solutions
Solution 1 (Click to Show/Hide)
function largestPrimeFactor(number) {
let prime = 2,
max = 1;
while (prime <= number) {
if (number % prime == 0) {
max = prime;
number = number / prime;
} else prime++; //Only increment the prime number if the number isn't divisible by it
}
return max;
}