#541. 「Nowcoder多校 2019 Day1」Euclidean Distance

「Nowcoder多校 2019 Day1」Euclidean Distance

题目描述

Bobo has a point A in the n dimension real space Rn\mathbb{R}^n , whose coodinate is (a1/m,a2/m,,an/m) (a_1 / m, a_2 / m, \dots, a_n / m) where ai a_i and m are both integers. He wants to find another point P=(p1,p2,,pn) P = (p_1, p_2, \dots, p_n) meeting the following requirements.

  • p1,p2,,pnR p_1, p_2, \dots, p_n \in \mathbb{R} . That is, they are real numbers.
  • p1,p2,,pn0 p_1, p_2, \dots, p_n \geq 0
  • p1+p2++pn=1 p_1 + p_2 + \dots + p_n = 1
  • The (squared) Euclidean distance between P and A, which is AP22=i=1n(ai/mpi)2 \|A - P\|_2^2 = \sum_{i = 1}^n (a_i / m - p_i)^2 , is minimized.

It can be proved the minimum is always a rational number. Print the squared distance in fraction. Note to print an integer n as n instead of n/1.

输入格式

The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains two integers n and m. The second line contains n integers a1,a2,,an a_1, a_2, \dots, a_n .

  • 1n104 1 \leq n \leq 10^4
  • 1m103 1 \leq m \leq 10^3
  • maim -m \leq a_i \leq m
  • The sum of n does not exceed 5×105 5 \times 10^5 .

输出格式

For each test case, print a fraction which denotes the result.

样例

样例输入 1

1 1
0
2 3
1 2
3 10
1 -2 3

样例输出 1

1
0
16/75