#include using namespace std; long longestSequence(long in, unordered_map& table){ if (in == 1){ return 1; } unordered_map::iterator found = table.find(in); if (found != table.end()){ return found->second; } long max = in + 1; for (long i = 2; i < (long)sqrt(in)+1; i++){ if (in % i == 0){ long divident = in/i; long localMax = i*longestSequence(divident, table) + 1; if (divident != i){ long temp = divident*longestSequence(i, table) +1; localMax = temp > localMax ? temp : localMax; } max = localMax > max ? localMax : max; } } table.insert({{in, max}}); return max; } long longestSequence(vector & a) { // Return the length of the longest possible sequence of moves. long total = 0; unordered_map table; for (int i = 0; i < a.size(); i++){ total += longestSequence(a[i], table); } return total; } int main() { int n; cin >> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } long result = longestSequence(a); cout << result << endl; return 0; }