Gingerbread

시간 제한2초메모리 제한2048 MB

요약
n개 상자에 쿠키를 최소한으로 더해 모든 상자의 쿠키 개수의 최대공약수가 1이 되도록 한다.
난이도

어려움10점 중 8점

유형
정수론, 수학, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

Toruń has been known for its traditional gingerbread since the Middle Ages. Young Nicolaus would like to buy a set of nn 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 ii-th box initially contains a_ia\_i 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 11. 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 11.


∗^∗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 nn (2≤n≤1062 ≤ n ≤ 10^6), denoting the number of boxes.

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \dots , a\_n (1≤a_i≤1071 ≤ a\_i ≤ 10^7), where the ii-th integer a_ia\_i denotes the initial number of cookies in the ii-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 11, output 00.

힌트

Explanation of the example: Indeed, the greatest common divisor (GCD) of 9090, 8484, and 140140 is 22, so some cookies must be added. If we add only one cookie, we may obtain the quantities 9191, 8484, 140140 with GCD of 77, or 9090, 8585, 140140 with GCD of 55, or 9090, 8484, 141141 with GCD of 33, so this is not enough. After adding two cookies, one to the first box, and one to the second box, we obtain the quantities 9191, 8585, 140140 with GCD of 11; hence the answer is 22. Note that adding both cookies to the first box does not help: we obtain quantities 9292, 8484, 140140 with GCD of 44.

예제1

  1. 예제 1

    입력
    3
    90 84 140
    
    예상 출력
    2