对于 ,只需要使用 unsigned long long 的自然溢出实现即可。
考虑优化,因为模数不是质数,所以答案很可能会是 。
因为只要两数奇偶性相同,就至少生出 个 的质因子 。
所以对于很大的 ,答案一定是 。
暴力枚举,乘完一项后,如果答案变成 ,就输出 ,否则继续,最后输出。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int M = 64;
int n;
unsigned long long a[N];
void solve()
{
scanf("%d",&n);
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1,a + n + 1);
for(int i = 1; i < n; i++)
if(a[i] == a[i + 1])
{
printf("0\n");
return;
}
unsigned long long total = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j < i; j++)
{
total *= (a[i] ^ a[j]);
if(total == 0)
{
printf("0\n");
return;
}
}
cout << total << "\n";
}
signed main()
{
cin.tie(0); cout.tie(0);
int T; scanf("%d",&T);
while(T--) solve();
}