#!/bin/python3 import sys # # def longestSequence( arr , is_DeBug_Mode: bool = 1 == 0 ) -> int: """ Return the length of the longest possible sequence of moves. expected: split * x1 + eat * x2 = 10 (6) 1 + 1 + 1 + 1 + 1 + 1 move(1) 1 + 1 1 + 1 1 + 1 split:1 each by 2 move(2) 1 1 1 1 1 1 split:3 each by 2 move(4) 1 1 1 1 1 1 eat:6 total: 10 expected: split * x1 + eat * x2 = 8 (7) 1 + 1 + 1 + 1 + 1 + 1 + 1 move(1) 1 1 1 1 1 1 1 split:1 each by 7 move(2) 1 1 1 1 1 1 1 eat:7 total: 10 so, actual task is in each step find minimum factor > 1 or is_Prime """ total_Sum = 0 # ordered ? primes_Set = { 2, 3, 5, 7, 11, 13, 17, 19 } # def not_Prime( n ) -> bool: """ @toDo: add primes_Set update here ? """ # return n not in primes_Set # def find_Min_Factor( n ) -> int: """ if not found => n is prime ? @toDo: add primes_Set update """ for p in primes_Set: if n % p == 0: return p # fail return n # for n in arr: # magic goes here if is_DeBug_Mode and 1 == 1: print( "n:{:d}, total_Sum:{:d}".format( n, total_Sum ) , file = sys.stderr ) min_Factor = 1 # of min_Factor size groups_Total = 1 # while n > 1 and not_Prime( n ): # min_Factor = find_Min_Factor( n ) # update total_Sum += groups_Total # n equal groups of min_Factor size groups_Total = groups_Total * n // min_Factor if is_DeBug_Mode and 1 == 1: print( "\tmin_Factor:{:d} * groups_Total:{:d} = n:{:d}, total_Sum:{:d}".format( min_Factor, groups_Total, n, total_Sum ) , file = sys.stderr ) n = min_Factor # if n == 1: total_Sum += groups_Total else: total_Sum += groups_Total * n if is_DeBug_Mode and 1 == 1: print( "-> sub_Sum:{:d}, min_Factor:{:d}, n:{:d}, groups_Total:{:d}".format( total_Sum, min_Factor, n, groups_Total ) , file = sys.stderr ) # return total_Sum # if __name__ == "__main__": # is_DeBug_Mode = 1 == 0 n = int( input().strip() ) arr = list( map( int, input().strip().split(' ') ) ) if is_DeBug_Mode and 1 == 1: print( "n:{:d}, arr:{}".format( n, arr[:42] ) , file = sys.stderr ) result = longestSequence( arr ) print( result )