#include #include #include using namespace std; void lastPrimeFactor(unsigned long long num, unsigned long long & last) { for (unsigned long long count = 2; count <= sqrt(num); count++) { if (num % count == 0) { num /= count; count = 1; } } last = num; } unsigned long long longestSequence(unsigned long long array[], int size) { unsigned long long totalMoves = 0; for (int index = 0; index < size; index++) { bool factorFound = true; unsigned long long firstFactor = 1; unsigned long long num = array[index]; while (firstFactor != num) { num = num / firstFactor; lastPrimeFactor(num, firstFactor); totalMoves += array[index] / num; } totalMoves += array[index]; } return totalMoves; } int main() { int numSticks = 0; cin >> numSticks; unsigned long long sticks[100] = {0}; for (int count = 0; count < numSticks; count++) cin >> sticks[count]; cout << longestSequence(sticks, numSticks) << endl; return 0; }