【Codeforces1305C】Kuroni and Impossible Calculation(数学)

题目大意

给出长度为\(n(1\le n\le 2\times 10^5)\)的数组\(a\)和数\(m(1\le m\le 1000)\),求\((\prod_{1\le i\le j\le n}|a_i-a_j|)\mod m\)


\(n\le m\)时,直接枚举\(i\)\(j\)计算答案即可。

\(n>m\)时,根据抽屉原理,必定存在\(i,j(i\neq j)\)使得\(a_i\equiv b_j(\mod m)\)

所以\(a_i-b_j\equiv 0(\mod m)\)

所以\(\prod_{1\le i\le j\le n}|a_i-a_j|\equiv 0(\mod m)\)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a[200000+10];
int main(){
	cin >> n >> m;
	for(ll i=1;i<=n;i++)cin >> a[i];
	if(n<=m){
		ll ans=1;
		for(ll i=1;i<=n;i++){
			for(ll j=i+1;j<=n;j++){
				ans*=abs(a[i]-a[j]);
				ans%=m;
			}
		}
		cout << ans;
	}else{
		cout << 0;
	}
	return 0;
}
posted @ 2023-08-31 21:21  Alric  阅读(20)  评论(0编辑  收藏  举报