Untitled
unknown
c_cpp
2 years ago
700 B
14
Indexable
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX = 2e5+5;
map<int, int> mp;
int ns[MAX];
signed main() {
cin.tie(nullptr)->sync_with_stdio(0);
int n; cin>>n;
int ans = 0;
for(int i = 0; i < n; ++i) {
cin>>ns[i];
++mp[ns[i]];
}
for(int i = 0; i < n; ++i) {
if(ns[i] == 1) {
ans += mp[1] - 1;
continue;
}
ans += mp[1];
ans += mp[ns[i]] - 1;
for(int j = 2; j <= (int)sqrt(ns[i])+1; ++j) {
if(j >= ns[i]) continue;
if(ns[i] % j == 0) {
ans += mp[j];
if(ns[i] / j != j) {
ans += mp[ns[i] / j];
}
}
}
}
cout<<ans<<'\n';
}Editor is loading...
Leave a Comment