logo AlgoBeat OnlineJudge
登录 注册

#212500. [BalticOI 2025] Gingerbread

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 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 1. 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 1.

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 , denoting the number of boxes.

The second line contains integers , 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 1, output 0.

样例

样例输入 1

3
90 84 140

样例输出 1

2

数据范围与提示

Explanation of the example: Indeed, the greatest common divisor (GCD) of 90, 84, and 140 is 2, so some cookies must be added. If we add only one cookie, we may obtain the quantities 91, 84, 140 with GCD of 7, or 90, 85, 140 with GCD of 5, or 90, 84, 141 with GCD of 3, so this is not enough. After adding two cookies, one to the first box, and one to the second box, we obtain the quantities 91, 85, 140 with GCD of 1; hence the answer is 2. Note that adding both cookies to the first box does not help: we obtain quantities 92, 84, 140 with GCD of 4.

Scoring

Subtask Constraints Points
1 17
2 34
3 11
4 No additional constraints. 38