#include using namespace std; #define BUFFER_SIZE 10000000 long *buffer; long maximum_moves(long length) { long max_moves = 0, moves = 0; if(length == 1) return 1; if(length < BUFFER_SIZE && buffer[length] != 0) return buffer[length]; for(int i = 2; i <= length/2; i++) { if(!(length % i)) { moves = i * maximum_moves(length/i); if(max_moves < moves) max_moves = moves; } } if(length > max_moves) max_moves = length; if(length < BUFFER_SIZE && buffer[length] != 0) buffer[length] = max_moves; return 1 + max_moves; } long longestSequence(vector a) { long total_moves = 0; buffer = new long[BUFFER_SIZE]; for(long chocolate_length : a) total_moves += maximum_moves(chocolate_length); return total_moves; } 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; }