Untitled
user_5379400
plain_text
a year ago
944 B
15
Indexable
#include<bits/stdc++.h>
using namespace std;
int n;
int a[2005];
map<pair<int, int>, int> mp;
pair<int, int> get(int a, int b){
int gcd = __gcd(a, b);
return {a / gcd, b / gcd};
}
void input(){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
mp.clear();
}
void solve(int testcase){
input();
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
mp[get(a[i], a[j])]++;
}
}
long long ans = 0;
for (int i = n; i >= 3; i--){
for (int j = i - 1; j >= 1; j--) mp[get(a[j], a[i])]--;
for (int j = i + 1; j <= n; j++){
ans += mp[get(a[i], a[j])];
}
}
cout << "#" << testcase << ' ' << ans << '\n';
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false), cin.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) solve(i);
}Editor is loading...
Leave a Comment