No.2046 Ans Mod? Mod Ans!
タグ : / 解いたユーザー数 91
作問者 : 👑
hitonanode
Story
Koboshi-san is solving competitive programming problems. One problem stated the following:
Since the answer can be very large, print the remainder when $10^9+7$ is divided by the answer.
Koboshi-san misread this as "print the remainder when the answer is divided by $10^9+7$", and so could not solve it.
Feeling sad, Koboshi-san decided to investigate the error between the correct output and Koboshi-san's output. When the answer is $X$ and the divisor is $Y$, this error is expressed as $|(X\bmod{Y})-(Y\bmod{X})|$.
Based on this, Koboshi-san created the following problem.
Problem Statement
Given pairwise distinct positive integers $A_1,A_2,\ldots,A_N$, find the value of
$$\sum_{i=1}^{N-1}\sum_{j=i+1}^N|(A_i\bmod{A_j})-(A_j\bmod{A_i})|$$.
Here, $a\bmod{b}$ denotes the remainder when $a$ is divided by $b$.
Pay attention to the execution time limit.
Constraints
- $2\le N\le 2\times 10^5$
- $1\le A_i\le 2\times 10^5$
- If $i\ne j$, then $A_i\ne A_j$
- All inputs are integers
Input
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
Output
Print the answer.
Sample
Sample 1
Input
2 3 5
Output
1
$|(3\bmod{5})-(5\bmod{3})|=|3-2|=1$.
Sample 2
Input
3 1 11 111
Output
12
Sample 3
Input
9 1 9 2 8 3 7 4 6 5
Output
83
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。