Applying above discussed formula for every array element
let mul = 1 ; for ( let i = 0 ; i < factors [ num ] . length ; i ++ ) mul *= Math . floor ( ( Math . pow ( factors [ num ] [ i ] . F , factors [ num ] [ i ] . S + 1 ) - 1 ) / ( factors [ num ] [ i ] . F - 1 ) ) ; return mul - num ; }