#include using namespace std; const int PD_MAX = 1e6 + 1; long movesCount[PD_MAX]; int primesV[PD_MAX]; long totalMoves(const long&); void initPD() { int iPrime = 0; for(int i = 1;i < PD_MAX;i++) { primesV[i] = 0; movesCount[i] = -1; movesCount[i] = totalMoves(i); if(movesCount[i] == i + 1) { primesV[iPrime] = i; iPrime++; } } } long totalMoves(const long &n) { long moves = 0; int iPrime = 0; if(n < PD_MAX && movesCount[n] != -1) { return movesCount[n]; } // prime decomposition of n for(int iPrime = 0;iPrime < PD_MAX ;iPrime++) { long pVal = primesV[iPrime]; if(n == 1 || pVal == 0 || pVal * pVal > n) { break; } if(n % pVal == 0) { moves = moves + n; return moves + totalMoves(n / pVal); } } if(n != 1) { moves = moves + n; } moves = moves + 1; return moves; } long longestSequence(long *a, int n) { // Return the length of the longest possible sequence of moves. initPD(); long solSum = 0; for(int i = 0;i < n;i++) { solSum = solSum + totalMoves(a[i]); } return solSum; } int main(int argc, char* argv[]) { int n; cin >> n; long *a = new long[n]; for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } long result = longestSequence(a, n); cout << result; return 0; }