
😎나의풀이
function solution(e, starts) {
    
    const countArr = new Array(5000001).fill(0)
    
    for (let i = 1; i <= e; i++){
        for (let j = 1; j <= e / i; j++){
            countArr[i * j]++;
        }
    }
    
    
    const startsWithIndex = starts.map((val, idx) => [val, idx])
    startsWithIndex.sort((a,b) => a[0] - b[0])
    
    let maxNum = [0,0]
    const result = []
    for(let i = e; i > 0; i--){
        if(startsWithIndex.length === 0) break;
        const count = countArr[i]
        if(maxNum[0] <= count) maxNum = [count, i];
        if(startsWithIndex.at(-1)[0] === i){
            result.push([maxNum[1], startsWithIndex.at(-1)[1]])
            startsWithIndex.pop()
        }
    }
    
    result.sort((a,b)=> a[1] - b[1])
    return result.map(row => row[0])
}