Problem:
Electric Metronome

A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously.

He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomes’ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals.

Given the number of metronomes and their preset intervals t_i (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer d_i to the current interval setting of the i-th metronome, and report the minimum value of the sum of all d_i.

Input

The input is given in the following format.

N
t_1
t_2
:
t_N

The first line provides the number of metronomes N (1 ≤ N ≤ 105). Each of the subsequent N lines provides the preset ticking interval t_i (1 ≤ t_i ≤ 104) of the i-th metronome.

Output

Output the minimum value.

Sample Input 1

3
3
6
8

Sample Output 1

3

If we have three metronomes each with a ticking interval of 3, 6, and 8 seconds, respectively, simultaneous activation of these will produce a tick in unison every 24 seconds. By extending the interval by 1 second for the first, and 2 seconds for the second metronome, the interval of ticking in unison will be reduced to 8 seconds, which is the shortest possible for the system.

Sample Input 2

2
10
10

Sample Output 2

0

If two metronomes are both set to 10 seconds, then simultaneous activation will produce a tick in unison every 10 seconds, which is the shortest possible for this system.

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var list = new List<int>();
            var ans = 0;



            for (int i = 0; i < n; i++)
            {
                var t = ReadInt();
                list.Add(t);
            }
            var max = list.Max();


            var yakusuu = new List<int>() {};
            for (int i = 1; i <= max; i++)
            {
                if (max % i == 0)
                {
                    yakusuu.Add(i);
                }
            }
            

            for (int i = 0; i < n; i++)
            {
                ans += yakusuu[LowerBound(yakusuu.ToArray(), list[i])]-list[i];
            }
            WriteLine(ans);
        }

        //lower_bound https://webbibouroku.com/Blog/Article/cs-lowerbound-upperbound
        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}