#P4867. Maximum Value

Maximum Value

Maximum Value

题面翻译

  • 给定一个序列 aia_i,请找出两个数 i,ji,j,使得 aiaja_i \ge a_j,并且使得 aimodaja_i \bmod a_j 的值最大,求这个 aimodaja_i\bmod a_j 的最大值。
  • 对于 100%100\% 的数据,1n2×1051 \le n \le 2\times 10^51ai1061 \le a_i \le 10^6
  • Translated by 一只书虫仔 & QwQcOrz。

题目描述

You are given a sequence a a consisting of n n integers. Find the maximum possible value of (integer remainder of ai a_{i} divided by aj a_{j} ), where 1<=i,j<=n 1<=i,j<=n and ai>=aj a_{i}>=a_{j} .

输入格式

You are given a sequence a a consisting of n n integers. Find the maximum possible value of (integer remainder of ai a_{i} divided by aj a_{j} ), where 1<=i,j<=n 1<=i,j<=n and ai>=aj a_{i}>=a_{j} .

输出格式

Print the answer to the problem.

样例 #1

样例输入 #1

3
3 4 5

样例输出 #1

2