#!/bin/python import sys import math basic_primes = [2,3,5,7,11] # Arbitrary number of the smallest primes ''' Find smallest divisor using sieve of eratosthenes ''' def get_smallest_divisor(x): n = int(math.ceil(math.sqrt(x))) # Compare largest basic_prime with sqrt(x). # It means that we've tested all possible small divisors if basic_primes[-1] > n: return x # EXTEND SIEVE sieve = [True] * (n+1) sieve[0] = False sieve[1] = False for prime in basic_primes: num_multiples = int(math.floor((len(sieve) - prime - 1)/prime)) + 1 sieve[prime::prime] = [False] * num_multiples # Find next prime try: next_prime = sieve.index(True) except ValueError: # x is itself a prime # although not necessarily the next prime in the sequence next_prime = None return x while next_prime != None: prime = next_prime basic_primes.append(prime) # Is it the smallest divisor? if x % prime == 0: return prime # Continue to update sieve num_multiples = int(math.floor((len(sieve) - prime - 1)/prime)) + 1 sieve[prime::prime] = [False] * num_multiples try: next_prime = sieve[prime:].index(True) + prime # optimization to find index except ValueError: next_prime = None return x def get_next(x): if x == 1: return 0 # Find smallest divisor of x for prime in basic_primes: if x % prime == 0: return x / prime # Smallest divisor is not in basic_primes # Expensive step smallest_divisor = get_smallest_divisor(x) return x / smallest_divisor def longestSequence(array): # Return the length of the longest possible sequence of moves. longest_seq = 0 for stick in array: total_moves = stick next_moves = stick while next_moves != 0: next_moves = get_next(next_moves) total_moves += next_moves longest_seq += total_moves return longest_seq if __name__ == "__main__": n = int(raw_input().strip()) a = map(long, raw_input().strip().split(' ')) result = longestSequence(a) print result