#include using namespace std; long leastDivisor(long L, unordered_map& leastdiv){ if(leastdiv.find(L) != leastdiv.end()){ //cout<<"found save for "<& saved, unordered_map& leastdiv){ if(saved.find(L) != saved.end()) return saved[L]; long move = L; long oldL = L; //cout<<"move for "< 1){ long d = leastDivisor(L, leastdiv); //cout<<"least divisor for " << L << " is "<< d ; if (saved.find(L / d) != saved.end()){ move += saved[L / d]; //cout<<"use existing number for " << L/d << "=" << saved[L / d]<< endl; break; } move += L / d; L = L / d; //cout<<" now move = " << move << ", L ="<< L << endl; } //cout< a) { // Return the length of the longest possible sequence of moves. long move = 0; long moves = 0; unordered_map save; unordered_map leastdiv; leastdiv[1] = 1; leastdiv[2] = 2; leastdiv[3] = 3; for(int i = 0; i < a.size(); i++){ move = stick(a[i], save, leastdiv); //cout<<"move for "<< a[i] <<"="<< move << endl; moves += move; } 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; }