//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 105
#define oo 100000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct Edge {
    int v, rev;
    ll f, cap;
};

struct Flow {
    vector<vector<Edge> > g;
    vector<int> dist, pos;
    int n, s, t;

    void print() {
        fto(u, 0, n-1) {
            debug(u);
            for(Edge e: g[u]) {
                printf("%d %d %lld %lld\n", e.v, e.rev, e.f, e.cap);
            }
        }
    }

    void addEdge(int u, int v, ll cap) {
        Edge A = {v, sz(g[v]), 0, cap};
        Edge B = {u, sz(g[u]), 0, 0};
        g[u].pb(A);
        g[v].pb(B);
    }

    bool bfs() {
        dist.assign(n, -1);
        queue<int> q;
        q.push(s);
        dist[s] = 0;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for(Edge e: g[u]) {
                if (e.f == e.cap) continue;
                int v = e.v;
                if (dist[v] == -1) {
                    dist[v] = dist[u]+1;
                    q.push(v);
                }
            }
        }
        return (dist[t] != -1);
    }

    ll dfs(int u, ll f) {
        if (u == t)
            return f;
        for(int &i = pos[u]; i < sz(g[u]); ++i) {
            Edge &e = g[u][i];
            if (e.cap == e.f) continue;
            int v = e.v;
//            printf("%d %d\n", u, v);
            if (dist[v] == dist[u]+1) {
                ll df = dfs(v, min(f, e.cap-e.f));
                if (df > 0) {
                    e.f += df;
                    g[v][e.rev].f -= df;
                    //++i;
                    return df;
                }
            }
        }
        return 0;
    }

    ll maxFlow(int _s, int _t) {
        s = _s; t = _t;
        ll res = 0;
        while (bfs()) {
//            fto(u, 0, n-1) printf("%d ", dist[u]);
//            puts("");
            pos.assign(n, 0);
            while (ll x = dfs(s, oo)) {
//                debug(x);
                res += x;
            }
//            print();
        }
        return res;
    }

    Flow(int n): n(n) {
        g.assign(n, vector<Edge>());
    }
};

int n, a[maxN], id[maxN];
vector<int> l, r;

int main () {
    scanf("%d", &n);
    Flow f(n+2);

    ll ans = 0;
    fto(i, 1, n) {
        scanf("%d", &a[i]);
        if (a[i] >= 0) {
            f.addEdge(i, n+1, a[i]);
            ans += a[i];
        }
        else {
            f.addEdge(0, i, -a[i]);
        }
    }

    fto(i, 1, n) {
        for(int j = 2*i; j <= n; j += i) f.addEdge(i, j, oo);
    }

//    f.print();

//    fto(i, 1, n) printf("%d ", id[i]);
//    puts("");


    ll x = f.maxFlow(0, n+1);
//    debug(x);

    cout << ans-x;

    return 0;
}


Measured memory_bytes: 256