To become the king of Codeforces, Kuroni has to solve the following problem.
He is given n numbers . Help Kuroni to calculate . As result can be very big, output it modulo m.
If you are not familiar with short notation, is equal to . In other words, this is the product of for all .
Input
The first line contains two integers — number of numbers and modulo.
The second line contains n integers .
Output
Output the single number — .
輸入1:
2 10
8 5
輸出1:
3
輸入2:
3 12
1 4 5
輸出2:
0
輸入3:
3 7
1 4 9
輸出3:
1
題意: 給一個 個非負整數的序列,以及正整數,求 的值。
思路: 由抽屜原理可知,當 時,必定存在兩個 同餘,此時答案爲 0. 否則 n 小於等於 1000,可以直接暴力。
Code:
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=2e5+100;
ll a[N],ans=1;
int main(){
ll n,m; cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
if(n>m) return cout<<0<<endl,0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
ans=ans*(ll)abs(a[j]-a[i])%m;
cout<<ans<<endl;
return 0;
}