To store the maximum element from the original array
let maxEle = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { gcd = __gcd ( gcd , arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } let totalMoves = parseInt ( maxEle / gcd , 10 ) - n ;