A13173 | Kuroni and Impossible Calculation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
To become the king of Codeforces, Kuroni has to solve the following problem.
He is given $n$ numbers $a_1, a_2, \dots, a_n$ . Help Kuroni to calculate $\prod_{1\le i<j\le n} |a_i - a_j|$ . As result can be very big, output it modulo $m$ .
If you are not familiar with short notation, $\prod_{1\le i<j\le n} |a_i - a_j|$ is equal to $|a_1 - a_2|\cdot|a_1 - a_3|\cdot$ $\dots$ $\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot$ $\dots$ $\cdot|a_2 - a_n| \cdot$ $\dots$ $\cdot |a_{n-1} - a_n|$ . In other words, this is the product of $|a_i - a_j|$ for all $1\le i < j \le n$ .
He is given $n$ numbers $a_1, a_2, \dots, a_n$ . Help Kuroni to calculate $\prod_{1\le i<j\le n} |a_i - a_j|$ . As result can be very big, output it modulo $m$ .
If you are not familiar with short notation, $\prod_{1\le i<j\le n} |a_i - a_j|$ is equal to $|a_1 - a_2|\cdot|a_1 - a_3|\cdot$ $\dots$ $\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot$ $\dots$ $\cdot|a_2 - a_n| \cdot$ $\dots$ $\cdot |a_{n-1} - a_n|$ . In other words, this is the product of $|a_i - a_j|$ for all $1\le i < j \le n$ .
输入格式
The first line contains two integers $n$ , $m$ ( $2\le n \le 2\cdot 10^5$ , $1\le m \le 1000$ ) — number of numbers and modulo.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 10^9$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 10^9$ ).
输出格式
Output the single number — $\prod_{1\le i<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 \equiv 3 \bmod 10$ .
In the second sample, $|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12$ .
In the third sample, $|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7$ .
In the second sample, $|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12$ .
In the third sample, $|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted