解法一
✅ 完整代碼
評分結果(參考) : AC (5ms, 324KB)
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t, n, temp;
cin >> t;
for(int i=0; i<t; i++){
cin >> n;
unordered_map<int, int> um;
for(int j=0; j<n; j++){
cin >> temp;
um[temp*temp]++;
}
int ans = 0;
for(auto it1=um.begin(); it1!=um.end(); it1=next(it1)){
for(auto it2=next(it1); it2!=um.end(); it2=next(it2)){
int sum = it1->first + it2->first;
if(um.count(sum)){
ans += it1->second * it2->second * um[sum];
}
}
}
cout << ans << "\n";
}
return 0;
}