import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Created by Chezlui on 16/12/2017. */ public class Solution { static ArrayList dividers(long n) { ArrayList divisors = new ArrayList<>(); for (int d = 2; d <= n / 2; d++) { if (n % d == 0) { divisors.add(d); } } return divisors; } static void divideTillTheEnd(Stick stick) { if (stick.pieces == stick.totalSize) { if (stick.totalSize == 1) { stick.addChild(new Stick(1, 1, 1, 1)); return; } return; } ArrayList dividers = dividers(stick.pieceSize); for (Integer divider : dividers) { long pieceSize = stick.pieceSize / divider; long pieces = stick.totalSize / pieceSize; long moves = stick.moves + stick.pieces; stick.addChild(new Stick(stick.totalSize, pieceSize, pieces, moves)); } if (dividers.size() == 0) { //System.out.println("Alcanzado nodo con tamaƱo de pieza: " + stick.pieceSize + " y " + stick.pieces + " piezas"); stick.addChild(new Stick(stick.totalSize, 1, stick.totalSize, stick.moves + stick.pieces + stick.totalSize)); } for (Stick stickIt : stick.getChildren()) { divideTillTheEnd(stickIt); } } static long getMax(Stick stick) { long max = 0; if (stick.getChildren().size() > 0) { for (Stick stickIt : stick.getChildren()) { long potentialMax = getMax(stickIt); if (potentialMax > max) { max = potentialMax; } } return max; } else { return stick.moves; } } static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. long total = 0; for (long x : a) { ArrayList divisors = dividers(x); Stick root = new Stick(x, x, 1, 0); divideTillTheEnd(root); total += getMax(root); } return total; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] a = new long[n]; for (int a_i = 0; a_i < n; a_i++) { a[a_i] = in.nextLong(); } long result = longestSequence(a); System.out.println(result); in.close(); } private static class Stick { private List children = new ArrayList(); final public long totalSize; final public long pieceSize; final public long pieces; final public long moves; public Stick(long totalSize, long pieceSize, long pieces, long moves) { this.totalSize = totalSize; this.pieceSize = pieceSize; this.pieces = pieces; this.moves = moves; } public void addChild(Stick stick) { this.children.add(stick); } public List getChildren() { return this.children; } } }