time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
To become the king of Codeforces, Kuroni has to solve the following problem.
He is given n numbers a1,a2,…,an. Help Kuroni to calculate ∏1≤i If you are not familiar with short notation, ∏1≤i The first line contains two integers n, m (2≤n≤2⋅105, 1≤m≤1000) — number of numbers and modulo. The second line contains n integers a1,a2,…,an (0≤ai≤109). Output the single number — ∏ 1 ≤ i < j ≤ n ∣ a i − a j ∣ m o d m \prod_{1≤i 2 10 3 3 12 0 3 7 1 In the first sample, |8−5|=3≡3mod10. In the second sample, |1−4|⋅|1−5|⋅|4−5|=3⋅4⋅1=12≡0mod12. In the third sample, |1−4|⋅|1−9|⋅|4−9|=3⋅8⋅5=120≡1mod7. 计算出 ∏ 1 ≤ i < j ≤ n ∣ a i − a j ∣ m o d m \prod_{1≤i 如果用纯暴力的话2*105肯定会超时,但是这里有一个鸽巢定理和取模运算,因为((a % mod - b % mod) + mod) % mod = (a - b + mod) % mod所以把全部数取余后,加入n超过了m的话,那么一定有一个数重复,重复的话,相减就为0,那么取模一定为0,这就是鸽巢原理,如果不懂那么点这里,这样最坏的情况就是O(10002)然后暴力就可以了。Input
Output
Examples
input
8 5output
input
1 4 5output
input
1 4 9output
Note
题意:
思路:
#include