Untitled

 avatar
user_5379400
plain_text
2 months ago
944 B
6
Indexable
Never
#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);
}
Leave a Comment