No.2260 Adic Sum
タグ : / 解いたユーザー数 166
作問者 :
sotanishy
Problem Statement
For a positive integer $n$, let $v_p(n)$ denote the number of times $n$ is divisible by a prime $p$.
More precisely, for a positive integer $n$, there uniquely exists a pair of a non-negative integer $k$ and an integer $m$ with $m\not\equiv 0\mod{p}$ such that $n=p^km$, and we define $v_p(n)=k$.
You are given a prime $P$ and a sequence of positive integers $A=(A_1,A_2,\dots,A_N)$ of length $N$ whose values are all distinct.
Find $$\sum_{i=1}^{N-1}\sum_{j=i+1}^{N}v_P(|A_i-A_j|)$$
.
Input
$N$ $P$ $A_1$ $A_2$ $\dots$ $A_N$
- $2 \leq N \leq 10^5$
- $2 \leq P \le 10^9$
- $P$ is a prime
- $1 \leq A_i \le 10^9$
- $A_i\neq A_j$ if $i\neq j$
- All input values are integers
Output
Print a newline at the end.
Sample
Sample 1
Input
3 2 1 3 5
Output
4
We have $v_P(|1-3|)=1$, $v_P(|1-5|)=2$, $v_P(|3-5|)=1$.
Therefore, print $1+2+1=4$.
Sample 2
Input
5 5 5 55 555 5555 55555
Output
30
Sample 3
Input
8 3 7023 2800 6599 9703 543 4221 1307 6572
Output
18
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。