判断 \prod a[i]! == \prod b[i]! ?
判断 \(\prod_{i=1}^{n}a[i]! == \prod_{i=1}^{m}b[i]!\)
做法:找两个模数,算一下比较一下就好了。如果上式相等那计算取模也一定相等。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; ++ i)
#define per(i, a, n) for(int i = n; i >= a; -- i)
#define px first
#define py second
typedef long long ll;
typedef pair<ll,ll>PII;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
//
ll Mod[5] = {1000000007, 998244353, 157492211};
int n, m;
ll a[N], b[N];
ll fac[5][N];
int main()
{
fac[0][0] = fac[1][0] = fac[2][0] = 1;
for(int z = 0; z <= 2; ++ z){
for(ll i = 1; i < N; ++ i){
fac[z][i] = fac[z][i - 1] * i % Mod[z];
}
}
int T; scanf("%d",&T);
while(T --){
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; ++ i) scanf("%lld",&a[i]);
for(int i = 1; i <= m; ++ i) scanf("%lld",&b[i]);
int flag = 0;
for(int z = 2; z <= 2; ++ z){
ll res1 = 1, res2 = 1;
for(int i = 1; i <= n; ++ i) res1 = (res1 * fac[z][a[i]]) % Mod[z];
for(int i = 1; i <= m; ++ i) res2 = (res2 * fac[z][b[i]]) % Mod[z];
if(res1 != res2){
flag = 1;
break;
}
}
if(flag) printf("unequal\n");
else printf("equal\n");
}
return 0;
}