#P7521. [省选联考 2021 B 卷] 取模

    ID: 8430 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>各省省选2021O2优化

[省选联考 2021 B 卷] 取模

Problem Description

Given nn positive integers aia_i, please choose three numbers i,j,ki, j, k (i≠ji \ne j, i≠ki \ne k, j≠kj \ne k) such that the value of (ai+aj) mod ak(a_i + a_j) \bmod a_k is maximized.

Input Format

The first line contains an integer nn, indicating the number of integers.
The second line contains nn integers, indicating aia_i.

Output Format

Output one line with one integer, indicating the answer.

6
4 7 7 5 2 2

6

见附件中的 mod/mod2.in。
见附件中的 mod/mod2.ans。

Hint

For 30%30\% of the testdata, n≤100n \le 100.
For 60%60\% of the testdata, n≤3000n \le 3000.
For 100%100\% of the testdata, 3≤n≤2×1053 \le n \le 2 \times {10}^5, 1≤ai≤1081 \le a_i \le {10}^8.

Translated by ChatGPT 5