#include #include #include using namespace std; long seqPerBar(long n, int *lookup) { //cout << "seqPerBar(" << n << ")" << endl; if(n<=1) return 1; else if(lookup[n] != -1) return lookup[n]; long max = INT_MIN; for(int i=1;i < n ;i++) { if(n%i == 0) { int tmp = (n/i)*seqPerBar(i, lookup) ; if(tmp > max) { max = tmp; } //cout << "i = " << i << " max=" << max << endl; } } lookup[n] = max+1; return max+1; } long longestSequence(vector a) { // Return the length of the longest possible sequence of moves. int mx = *max_element(a.begin(),a.end()); int *lookup = new int[mx+1]; for(int i=0; i <= mx; i++) lookup[i] = -1; long total =0 ; for(int i=0; i < a.size(); i++) total = total+seqPerBar(a[i], lookup); 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; }