#include using namespace std; typedef long LONG; bool debug = false; #define DEBUGOUT if (debug) LONG longestSequence(vector a) { // Return the length of the long longest possible sequence of moves. auto I = a.begin(); auto Iend = a.end(); LONG moves = 0; LONG test_prime; LONG length; LONG i; LONG r; for( ; I != Iend; ++I) { length = *I; r = sqrtl(length)+1; DEBUGOUT cout << "Length: " << length << "\n"; DEBUGOUT cout << "~SQRT: " << r << "\n"; test_prime = 2; moves += length; while(/*length >= 2 &&*/ !(length-(length/2)*2)) { DEBUGOUT cout << "Faktor: " << 2 << "\n"; length /= 2; moves += length; DEBUGOUT cout << "Moves: " << moves << "\n"; } test_prime = 3; while(/*length >= 3 &&*/ !(length-(length/3)*3)) { DEBUGOUT cout << "Faktor: " << 3 << "\n"; length /= 3; moves += length; DEBUGOUT cout << "Moves: " << moves << "\n"; } i = 6; while(test_prime - 1 <= r) { test_prime = i-1; while(/*length >= test_prime &&*/ !(length-(length/test_prime)*test_prime)) { DEBUGOUT cout << "Faktor: " << test_prime << "\n"; length /= test_prime; moves += length; DEBUGOUT cout << "Moves: " << moves << "\n"; } test_prime = i+1; while(/*length >= test_prime &&*/ !(length-(length/test_prime)*test_prime)) { DEBUGOUT cout << "Faktor: " << test_prime << "\n"; length /= test_prime; moves += length; DEBUGOUT cout << "Moves: " << moves << "\n"; } i+=6; } if (length > 1) ++moves; } return 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; }