Source Code
//#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
  
void Fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void File() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
typedef long long ll;
void justify(int n,int x)
{
    string s=to_string(n);
    for(int i=0;i<x-s.size();i++)cout<<' ';
    cout<<s;
}
const int N=1e5+20;
vector<int>v[N];
void seive()
{
    for(int i=1;i<=100000;i++)
    {
        for(int j=i;j<=100000;j+=i)
            v[j].push_back(i);
    }
    
}
int a[N];
void solve()
{
    int n;
    cin>>n;
    ll res=0;
    map<int,int>mp;
    for (int i = 1; i <= n; i++)
    {
        cin>>a[i];
        
    }
    for (int i = 1; i <= n; i++)
    {
        for(auto x:v[a[i]])
        {
            res+=1ll*mp[x]*(n-i+1);
        }
        mp[a[i]]+=i;
    }
    cout<<res<<'\n';
}
int main()
{
    File();
    Fast();
    seive();
    int t=1;
    cin>>t;
    for (int i = 1; i <= t;i++ )
    {
        //cout<<"Case "<<i<<": ";
        solve();
    }

}
Copy
Powerful Inversions Ahmed_Aladdin
GNU G++17
608 ms
12.3 MB
Wrong Answer