CF1305C.Kuroni and Impossible Calculation

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

To become the king of Codeforces, Kuroni has to solve the following problem.

He is given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n. Help Kuroni to calculate ∏1≤i<j≤n∣ai−aj∣\prod_{1\le i \lt j\le n} |a_i - a_j|. As result can be very big, output it modulo mm.

If you are not familiar with short notation, ∏1≤i<j≤n∣ai−aj∣\prod_{1\le i \lt j\le n} |a_i - a_j| is equal to ∣a1−a2∣⋅∣a1−a3∣⋅|a_1 - a_2|\cdot|a_1 - a_3|\cdot …\dots ⋅∣a1−an∣⋅∣a2−a3∣⋅∣a2−a4∣⋅\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot …\dots ⋅∣a2−an∣⋅\cdot|a_2 - a_n| \cdot …\dots ⋅∣an−1−an∣\cdot |a_{n-1} - a_n|. In other words, this is the product of ∣ai−aj∣|a_i - a_j| for all 1≤i<j≤n1\le i \lt j \le n.

要成为 Codeforces 的王者,Kuroni 必须解决以下问题。

他被给定 nn 个数 a1,a2,…,ana_1, a_2, \dots, a_n。请帮助 Kuroni 计算 ∏1≤i<j≤n∣ai−aj∣\prod_{1\le i \lt j\le n} |a_i - a_j|。由于结果可能非常大,请输出其对 mm 取模的值。

若你不熟悉这种简写记号,则 ∏1≤i<j≤n∣ai−aj∣\prod_{1\le i \lt j\le n} |a_i - a_j| 等于 ∣a1−a2∣⋅∣a1−a3∣⋅|a_1 - a_2|\cdot|a_1 - a_3|\cdot …\dots ⋅∣a1−an∣⋅∣a2−a3∣⋅∣a2−a4∣⋅\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot …\dots ⋅∣a2−an∣⋅\cdot|a_2 - a_n| \cdot …\dots ⋅∣an−1−an∣\cdot |a_{n-1} - a_n|。换言之,这是对所有满足 1≤i<j≤n1\le i \lt j \le n 的 ∣ai−aj∣|a_i - a_j| 的乘积。

输入格式

The first line contains two integers nn, mm (2≤n≤2⋅1052\le n \le 2\cdot 10^5, 1≤m≤10001\le m \le 1000) — number of numbers and modulo.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \le a_i \le 10^9).

第一行包含两个整数 nn、mm(2≤n≤2⋅1052\le n \le 2\cdot 10^5,1≤m≤10001\le m \le 1000)——分别为数字的个数和模数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^9)。

输出格式

Output the single number — ∏1≤i<j≤n∣ai−aj∣ mod m\prod_{1\le i \lt j\le n} |a_i - a_j| \bmod m.

输出单个数字 — ∏1≤i<j≤n∣ai−aj∣ mod m\prod_{1\le i \lt j\le n} |a_i - a_j| \bmod m。

输入输出样例

  • 输入#1

    2 10
    8 5

    输出#1

    3
  • 输入#2

    3 12
    1 4 5

    输出#2

    0
  • 输入#3

    3 7
    1 4 9

    输出#3

    1

说明/提示

In the first sample, ∣8−5∣=3≡3 mod 10|8 - 5| = 3 \equiv 3 \bmod 10.

In the second sample, ∣1−4∣⋅∣1−5∣⋅∣4−5∣=3⋅4⋅1=12≡0 mod 12|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12.

In the third sample, ∣1−4∣⋅∣1−9∣⋅∣4−9∣=3⋅8⋅5=120≡1 mod 7|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7.

在第一个样例中,∣8−5∣=3≡3 mod 10|8 - 5| = 3 \equiv 3 \bmod 10。

在第二个样例中,∣1−4∣⋅∣1−5∣⋅∣4−5∣=3⋅4⋅1=12≡0 mod 12|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12。

在第三个样例中,∣1−4∣⋅∣1−9∣⋅∣4−9∣=3⋅8⋅5=120≡1 mod 7|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7。

输入解题思路,AI测评打分。不知道怎么写?

首页