Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Latest commit

 

History

History
32 lines (27 loc) · 667 Bytes

0005.md

File metadata and controls

32 lines (27 loc) · 667 Bytes
let primes = new Map();

for (let i=2; i<=20; i++) {
    let curr = i;
    let currPrimes = new Map();

    for (let p of primes.keys()) {
        while (curr % p === 0) {
            curr /= p;
            let currTimes = currPrimes.get(p) || 0;
            currPrimes.set(p, currTimes + 1);
        }
    }
    if (curr !== 1) {
        currPrimes.set(curr, 1);
    }

    for (let [p, times] of currPrimes) {
        let globalTimes = primes.get(p) || 0;
        // max times of primes
        primes.set(p, Math.max(globalTimes, times));
    }
}

let ret = 1;
for (let [p, times] of primes) {
    ret *= Math.pow(p, times);
}

console.log(ret);