import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            Vertex[] vertices = new Vertex[n + 1];
            for (int i = 0; i <= n; i++)
                vertices[i] = new Vertex();
            Vertex s = new Vertex();
            Vertex t = new Vertex();
            long sum = 0;
            for (int i = 1; i <= n; i++) {
                long a = in.nextLong();
                if (a <= 0) {
                    Edge e = new Edge(s, vertices[i], -a);
                    e.setReverseEdge();
                } else {
                    Edge e = new Edge(vertices[i], t, a);
                    e.setReverseEdge();
                    sum += a;
                }
                for (int j = i + i; j <= n; j += i) {
                    Edge e = new Edge(vertices[i], vertices[j], Long.MAX_VALUE);
                    e.setReverseEdge();
                }
            }

            out.println(sum - Search.maxFlow(s, t));
        }

    }

    static class Vertex {
        private long value;
        private long dist;
        private List<Edge> edges = new ArrayList<>();

        public Vertex() {
        }

        public Vertex(long v) {
            this.value = v;
        }

        public void setEdge(Edge e) {
            this.edges.add(e);
        }

        public long getDegree() {
            return this.edges.size();
        }

        public Edge getEdge(int index) {
            return this.edges.get(index);
        }

        public void setDist(long dist) {
            this.dist = dist;
        }

        public long getDist() {
            return dist;
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }

    static class Search {
        private static Set<Vertex> checked = new HashSet<>();
        private static Map<Vertex, Integer> start = new HashMap<>();

        public static long maxFlow(Vertex source, Vertex sink) {
            long flow = 0;
            while (true) {
                setDistBFS(source);
                if (sink.getDist() <= 0)
                    return flow;
                start.clear();
                long f = sendFlowDFS(source, sink, Long.MAX_VALUE);
                while (f > 0) {
                    flow += f;
                    f = sendFlowDFS(source, sink, Long.MAX_VALUE);
                }
            }
        }

        private static void setDistBFS(Vertex start) {
            Queue<Vertex> q = new ArrayDeque<>();
            q.add(start);
            for (Vertex cv : checked)
                cv.setDist(-1);
            checked.clear();
            checked.add(start);
            start.setDist(0);
            while (!q.isEmpty()) {
                Vertex cv = q.poll();
                for (int i = 0; i < cv.getDegree(); i++) {
                    Edge ce = cv.getEdge(i);
                    if (ce.getCost() > 0 && !checked.contains(ce.getTo())) {
                        ce.getTo().setDist(cv.getDist() + 1);
                        q.add(ce.getTo());
                        checked.add(ce.getTo());
                    }
                }
            }
        }

        private static long sendFlowDFS(Vertex cv, Vertex source, long f) {
            if (cv == source)
                return f;
            for (int i = start.getOrDefault(cv, 0); i < cv.getDegree(); i++) {
                Edge e = cv.getEdge(i);
                Vertex to = e.getTo();
                if (e.getCost() > 0 && cv.getDist() < to.getDist()) {
                    long d = sendFlowDFS(to, source, Math.min(f, e.getCost()));
                    if (d > 0) {
                        e.addCost(-d);
                        e.getReverseEdge().addCost(d);
                        return d;
                    }
                }
                start.put(cv, i);
            }
            return -1;
        }

    }

    static class Edge {
        private Vertex from;
        private Vertex to;
        private long cost;
        private Edge reverseEdge;

        public Edge() {
        }

        public Edge(Vertex to) {
            this.to = to;
        }

        public Edge(Vertex to, long c) {
            this.to = to;
            this.cost = c;
        }

        public Edge(Vertex from, Vertex to, long c) {
            this.from = from;
            this.to = to;
            this.cost = c;
            from.setEdge(this);
        }

        public Vertex getTo() {
            return this.to;
        }

        public long getCost() {
            return this.cost;
        }

        public void addCost(long d) {
            cost += d;
        }

        public void setReverseEdge(Edge reverseEdge) {
            this.reverseEdge = reverseEdge;
        }

        public void setReverseEdge() {
            Edge r = new Edge(to, from, 0);
            reverseEdge = r;
            r.setReverseEdge(this);
        }

        public Edge getReverseEdge() {
            return reverseEdge;
        }

    }
}



Measured memory_bytes: 23380