#include using namespace std; std::map> cache; vector getPossiblePieces(long a){ long half = sqrt(a); vector divisors; std::map>::iterator it = cache.find(a); if (it != cache.end()){ return it->second; } for(long i = 1; i <= half ; i++){ if(a % i == 0){ divisors.push_back(i); if(a / i != i && a / i != a) { divisors.push_back(a / i); } } } cache[a] = divisors; return divisors; } long bfs(long node_value, long pieces){ //pieces = current node moves vector divisors; long max_child_path_moves = 0; long child_path_moves; if(node_value == 1){ return pieces; } divisors = getPossiblePieces(node_value); for(vector::iterator it = divisors.begin(); it != divisors.end() ; it++){ child_path_moves = bfs(*it, pieces * node_value / *it); if(child_path_moves > max_child_path_moves){ max_child_path_moves = child_path_moves; } } return max_child_path_moves + pieces; } long longestSequence(vector a) { // Return the length of the longest possible sequence of moves. long sum = 0; for(vector::iterator it = a.begin(); it != a.end() ; it++){ sum += bfs(*it, 1); } return sum; } 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; }