CodeForces 1305C. Kuroni and Impossible Calculation

传送门

题意

(a_1,a_2,...,a_n)(m(1le mle 1000)),求 (prod_{1le i<jle n}|a_i-a_j|\%m)

题解

又没把 C 题做出来,真的太蠢了
如果我想要 (prod_{1le i<jle n}|a_i-a_j|) 不是 (m) 的倍数
则所有 (a_i\%m) 各不相同,显然这在 (n>m) 的情况下是不可能存在的
那么如果 (n>m),那么结果显然为 (0)
否则暴力算结果。

代码

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=2e5+10;
const int M=2e6+10;
int n,m;
LL a[N];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	if(n>m) return printf("0
"),0;
	LL ans=1;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=ans*abs(a[i]-a[j])%m;
	printf("%lld
",ans);
	return 0;
}
原文地址:https://www.cnblogs.com/BakaCirno/p/12409265.html