luogu#P4549. 【模板】裴蜀定理

    ID: 3547 远端评测题 1000ms 64MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学最大公约数 gcd不定方程Bézout 定理

【模板】裴蜀定理

Problem Description

Given an integer sequence AA with nn elements, denoted as A1,A2,A3,,AnA_1, A_2, A_3, \ldots, A_n.

Find another integer sequence XX with nn elements. Let S=i=1nAi×XiS=\sum\limits_{i=1}^nA_i\times X_i, such that S>0S>0 and SS is as small as possible.

Input Format

The first line contains an integer nn, the number of elements in the sequence.

The second line contains nn integers, the sequence AA.

Output Format

Output a single integer on one line, the minimal value of SS subject to S>0S>0.

2
4059 -1782

99

Hint

Constraints: For 100%100\% of the testdata, 1n201 \le n \le 20, Ai105|A_i| \le 10^5, and the sequence AA is not all zeros.

Translated by ChatGPT 5