
fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val metronome = Array(n){readLine()!!.toInt()}.sortedArray()
    val fact = factor(metronome.last())
    println(metronome.sumBy{
        val num = fact[fact.upperBound(it)]
        num - it
    })
}
fun <T> Array<T>.upperBound(factor:T):Int {
    val idx = this.binarySearch(factor)
    return if (idx < 0) -idx - 1
    else idx
}
fun factor(num:Int):Array<Int> {
    return (1 .. num).filter{num % it == 0}.toTypedArray()
}
