#include using namespace std; class StickBreaker { unordered_map best_moves; unordered_map> divisors; set getAllDivisors2(long x) { if (divisors.find(x) != divisors.end()) { return divisors[x]; } set divs; divs.insert(x); long inc = 1; long start = 2; if ((x % 2) != 0) { inc = 2; start = 3; } for (long i = start; i <= sqrt(x) +1; i += inc) { if (x % i == 0) { divs.insert(i); divs.insert(x/i); set mul_1 = getAllDivisors2(i); set mul_2 = getAllDivisors2(x/i); divs.insert(mul_1.begin(), mul_1.end()); divs.insert(mul_2.begin(), mul_2.end()); } } divisors[x] = divs; return divisors[x]; } vector getAllDivisors(long x) { vector divs; divs.reserve(sqrt(x)+1); long inc = 1; long start = 2; if ((x % 2) != 0) { inc = 2; start = 3; } for (long i = start; i <= sqrt(x)+1; i += inc) { if (x % i == 0) { if ( x/i == i) { divs.push_back(i); } else { divs.push_back(i); divs.push_back(x/i); } } } return divs; } public: StickBreaker() { divisors[2].insert(2); best_moves[1] = 1; best_moves[2] = 3; best_moves[3] = 4; //optime_div[3] * best_moves[3/optime_div[3]] + 1; // 3 * best_moves[3/3] + 1 = 3 * best_moves[1] + 1 = 3 * 3 +1 =4 best_moves[4] = 7; ///optime_div[4] * best_moves[4/optime_div[4]] + 1; best_moves[5] = 6; best_moves[6] = 10; //optime_div[6] * best_moves[6/optime_div[6]] + 1; //10; // 3 * best_moves[6/3] + 1 = 3 * best_moves[2] + 1 = 3 * 3 +1 =10; } long longestMoves(long x) { if (best_moves.find(x) != best_moves.end()) { return best_moves[x]; } else { long best_mov = x + 1; vector divs = getAllDivisors(x); for (long i : divs) { if (( x % i ) == 0) { long cur_mov = 0; long cur_best = longestMoves(x/i); cur_mov = i * cur_best + 1; best_mov = max(best_mov, cur_mov); //cerr << "[ " << x << "] If div = " << i << " moves are " << cur_mov << endl; } } best_moves[x] = best_mov; } return best_moves[x]; } long longestSequence(vector & a) { long moves = 0; for (int i = 0; i < a.size(); i++) { long aux = longestMoves(a[i]); //cerr << "Longest moves of " << a[i] << " = " << aux << endl; moves += aux; //longestMoves(a[i]); } return moves; // Return the length of the longest possible sequence of moves. } }; int main() { int n; cin >> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } StickBreaker sb; sort(a.begin(), a.end()); long result = sb.longestSequence(a); cout << result << endl; return 0; }