#include <iostream>
#include <vector>
using namespace std;
const int MAX_VAL = 1e6; // Maximum possible value of elements in the array
// Function to calculate sum of GCD over all pairs
long long gcd_sum_over_pairs(const vector<int>& arr) {
// Step 1: Create a frequency array
vector<int> freq(MAX_VAL + 1, 0);
for (int num : arr) {
freq[num]++;
}
long long result = 0;
// Step 2: For each gcd value `g`, calculate how many multiples of `g` exist
for (int g = 1; g <= MAX_VAL; g++) {
// Count multiples of g
long long count_g = 0;
for (int multiple = g; multiple <= MAX_VAL; multiple += g) {
count_g += freq[multiple];
}
// If there are at least 2 numbers with GCD `g`, calculate the number of pairs
if (count_g >= 2) {
long long pairs_g = count_g * (count_g - 1) / 2; // Combinatorial formula nC2
result += g * pairs_g; // Add contribution of these pairs to the result
}
}
return result;
}
int main() {
int n;
cin >> n;
vector<int> arr;
int x;
for(int i = 0; i < n; ++i){
cin >> x;
arr.push_back(x);
}
cout << gcd_sum_over_pairs(arr) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9WQUwgPSAxZTY7ICAvLyBNYXhpbXVtIHBvc3NpYmxlIHZhbHVlIG9mIGVsZW1lbnRzIGluIHRoZSBhcnJheQoKLy8gRnVuY3Rpb24gdG8gY2FsY3VsYXRlIHN1bSBvZiBHQ0Qgb3ZlciBhbGwgcGFpcnMKbG9uZyBsb25nIGdjZF9zdW1fb3Zlcl9wYWlycyhjb25zdCB2ZWN0b3I8aW50PiYgYXJyKSB7CiAgICAvLyBTdGVwIDE6IENyZWF0ZSBhIGZyZXF1ZW5jeSBhcnJheQogICAgdmVjdG9yPGludD4gZnJlcShNQVhfVkFMICsgMSwgMCk7CiAgICBmb3IgKGludCBudW0gOiBhcnIpIHsKICAgICAgICBmcmVxW251bV0rKzsKICAgIH0KCiAgICBsb25nIGxvbmcgcmVzdWx0ID0gMDsKCiAgICAvLyBTdGVwIDI6IE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