#include<cstdio> #include<iostream> #include<vector> #define pb push_back usingnamespace std; typedeflonglong L; typedef vector <int> VI; constint N = 5e5 + 10; int n, w[N], v[N], cnt[N]; VI f[N], x[N], y[N]; intgcd(int a, int b) { return a ? gcd(b % a, a) : b; } voidinit() { for (int i = 1; i < N; ++i) for (int j = 1; i * j < N; ++j) f[i * j].pb(i); } intmain() { init(); int T; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; ++i) { cin >> w[i], v[i] = i; int d = gcd(w[i], v[i]); w[i] /= d, v[i] /= d; } for (int i = 1; i <= n; ++i) x[i].clear(), y[i].clear(); for (int i = 1; i <= n; ++i) x[w[i]].pb(i), y[v[i]].pb(i); L res = 0; for (int i = 1; i <= n; ++i) { for (int t : y[i]) for (int s : f[w[t]]) ++cnt[s]; for (int j = 1; i * j <= n; ++j) for (int k : x[i * j]) res += cnt[v[k]]; for (int t : y[i]) for (int s : f[w[t]]) --cnt[s]; } for (int i = 1; i <= n; ++i) res -= v[i] == 1; cout << (res >> 1) << endl; } return0; }