Logo
(追記) (追記ここまで)

33859번 - Gingerbread 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB108443742.529%

문제

Toruń has been known for its traditional gingerbread since the Middle Ages. Young Nicolaus would like to buy a set of $n$ 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 $i$-th box initially contains $a_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 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 $n$ (2ドル ≤ n ≤ 10^6$), denoting the number of boxes.

The second line contains $n$ integers $a_1, a_2, \dots , a_n$ (1ドル ≤ a_i ≤ 10^7$), where the $i$-th integer $a_i$ denotes the initial number of cookies in the $i$-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ドル$.

제한

서브태스크

번호배점제한
117

$n = 2$

234

$n ≤ 10$

311

$n ≤ 1000$

438

No additional constraints.

예제 입력 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ドル$.

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2025 F번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /