#include #include #include // std::greater #include // std::sort #include #include using namespace std; vector primefactors; void primeFactors(long n) { // Print the number of 2s that divide n while (n % 2 == 0) { //printf("%d ", 2); primefactors.push_back(2); n = n / 2; } // n must be odd at this point. So we can skip // one element (Note i = i +2) for (long i = 3; i <= sqrt(n); i = i + 2) { // While i divides n, print i and divide n while (n%i == 0) { //printf("%d ", i); primefactors.push_back(i); n = n / i; } } // This condition is to handle the case when n // is a prime number greater than 2 if (n > 2) { //printf("%d ", n); primefactors.push_back(n); } } long longestSequence(long a) { primefactors.resize(0); primeFactors(a); std::sort(begin(primefactors),end(primefactors),std::greater()); long product = 1; long sum = 1; for (int i = 0; i <(int)primefactors.size(); ++i) { product *= primefactors[i]; sum += product; } return sum; } long longestSequence(const vector & a) { // Return the length of the longest possible sequence of moves. long sum = 0; for (int i = 0; i <(int) a.size(); ++i) { sum += longestSequence(a[i]); } return sum; } int main() { //std::string input_filename = "input.txt"; //std::fstream fin(input_filename); std::istream& in = std::cin; //std::istream& in = fin; int n; in >> n; vector a(n); for (int a_i = 0; a_i < n; a_i++) { in >> a[a_i]; } long result = longestSequence(a); cout << result << endl; return 0; }