Gingerbread
문제
Toruń has been known for its traditional gingerbread since the Middle Ages. Young Nicolaus would like to buy a set of boxes with gingerbread cookies in his favourite shop. The shop has very strict rules, though: Nicolaus initially obtains n boxes that are already filled with cookies: the -th box initially contains of them. Then, Nicolaus can order some extra cookies. He adds extra cookies to some boxes so that the greatest common divisor^∗ of the numbers of cookies in all of the boxes becomes equal to . It can be proven that this is always possible.
Help Nicolaus by calculating the smallest number of cookies that need to be added in order to make the greatest common divisor of all the numbers equal to .
^∗The greatest common divisor (GCD) of multiple numbers is the largest positive integer that divides all of them without remainder.
입력
The first line contains an integer (2 ≤ n ≤ 10^6), denoting the number of boxes.
The second line contains integers (1 ≤ a_i ≤ 10^7), where the -th integer denotes the initial number of cookies in the -th box.
출력
Output one line with a single integer denoting the smallest number of cookies that Nicolaus should add to the boxes. If Nicolaus doesn’t have to add any cookies to make the greatest common divisor of the numbers equal to , output .
힌트
Explanation of the example: Indeed, the greatest common divisor (GCD) of , , and is , so some cookies must be added. If we add only one cookie, we may obtain the quantities , , with GCD of , or , , with GCD of , or , , with GCD of , so this is not enough. After adding two cookies, one to the first box, and one to the second box, we obtain the quantities , , with GCD of ; hence the answer is . Note that adding both cookies to the first box does not help: we obtain quantities , , with GCD of .
예제
예제 1
3 90 84 140
2