codeforces 1305C(鸽巢原理+同余)
题意:给定n个数,n个数两两做差取绝对值,所有差的绝对值做累乘,再对m取模,求这个模的值。
思路:n=2e5,m=1000.如果n大于m,n个数分别%m肯定会出现两个数%n的余数相等,则他俩%m的余数相减肯定为0,则答案为0.n小于等于m时,直接暴力即可1e6
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> //const int maxn = 1e5+5; #define ll long long #define inf 0x3f3f3f3f #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl #define P pair<int, int> #define fi first #define se second ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} using namespace std; const int maxn = 2e5 + 10; int a[maxn]; int main() { int n,m; ll ans = 1; cin>>n>>m; for(int i = 1;i <= n; ++i) cin>>a[i]; if(n > m){ cout<<0<<endl; return 0; } for(int i = 1;i <= n-1; ++i) { for(int j = i+1;j <= n; ++j) { ans = ((ans%m) *abs(a[i]-a[j])%m)%m; } } cout<<ans<<endl; }