// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



using ll = long long;



const int MAX_V = 10000;

const ll INF = 1e13;



struct Edge {

    int to;

    ll cap;

    int rev;  //行き先、容量、逆辺

    Edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}

};



vector<Edge> G[MAX_V];

int level[MAX_V];

int iter[MAX_V];



void add_edge(int from, int to, ll cap) {

    G[from].push_back(Edge(to, cap, G[to].size()));

    G[to].push_back(Edge(from, 0, G[from].size() - 1));

}



void bfs(int s) {

    memset(level, -1, sizeof(level));

    queue<int> que;

    level[s] = 0;

    que.push(s);

    while (!que.empty()) {

        int v = que.front();

        que.pop();

        for (int i = 0; i < G[v].size(); i++) {

            Edge& e = G[v][i];

            if (e.cap > 0 && level[e.to] < 0) {

                level[e.to] = level[v] + 1;

                que.push(e.to);

            }

        }

    }

}



ll dfs(int v, int t, ll f) {

    if (v == t) return f;

    for (int& i = iter[v]; i < G[v].size(); i++) {

        Edge& e = G[v][i];

        if (e.cap > 0 && level[v] < level[e.to]) {

            ll d = dfs(e.to, t, min(f, e.cap));

            if (d > 0) {

                e.cap -= d;

                G[e.to][e.rev].cap += d;

                return d;

            }

        }

    }

    return 0;

}



ll max_flow(int s, int t) {

    ll flow = 0;

    while (true) {

        bfs(s);

        if (level[t] < 0) return flow;

        memset(iter, 0, sizeof(iter));

        ll f;

        while ((f = dfs(s, t, INF)) > 0) {

            flow += f;

        }

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;



    ll ans = 0;

    for (int i = 0; i < n; i++) {

        ll a;

        cin >> a;

        if (a >= 0) {

            ans += a;

            add_edge(0, i + 1, a);

        } else {

            add_edge(i + 1, n + 1, -a);

        }

    }



    for (int i = 1; i <= n; i++) {

        for (int j = i * 2; j <= n; j += i) {

            add_edge(j, i, INF);

        }

    }

    

    ans -= max_flow(0, n + 1);

    cout << ans << "\n";

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3106557674792263x):
#include <bits/stdc++.h>



using namespace std;



using ll = long long;



const ll INF = 1e18;



struct Dinic {

    using T = ll;



    struct Edge {

        int to;

        T cap;

        int rev;  //行き先、容量、逆辺

        Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}

    };



    vector< vector<Edge> > G;

    vector<int> level, iter;



private:

    void bfs(int s) {

        fill(level.begin(), level.end(), -1);

        queue<int> que;

        level[s] = 0;

        que.push(s);

        while (!que.empty()) {

            int v = que.front();

            que.pop();

            for (const Edge& e : G[v]) {

                if (e.cap > 0 && level[e.to] < 0) {

                    level[e.to] = level[v] + 1;

                    que.push(e.to);

                }

            }

        }

    }



    T dfs(int v, int t, T f) {

        if (v == t) return f;

        for (int& i = iter[v]; i < G[v].size(); i++) {

            Edge& e = G[v][i];

            if (e.cap > 0 && level[v] < level[e.to]) {

                T d = dfs(e.to, t, min(f, e.cap));

                if (d > 0) {

                    e.cap -= d;

                    G[e.to][e.rev].cap += d;

                    return d;

                }

            }

        }

        return 0;

    }



public:

    Dinic(int V) : G(V), level(V, -1), iter(V, 0) {}



    void add_edge(int from, int to, T cap) {

        G[from].push_back(Edge(to, cap, G[to].size()));

        G[to].push_back(Edge(from, 0, G[from].size() - 1));

    }



    T max_flow(int s, int t) {

        T flow = 0;

        while (true) {

            bfs(s);

            if (level[t] < 0) return flow;

            fill(iter.begin(), iter.end(), 0);

            T f;

            while ((f = dfs(s, t, INF)) > 0) {

                flow += f;

            }

        }

    }

};



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    Dinic dinic(n + 2);



    ll ans = 0;

    for (int i = 0; i < n; i++) {

        ll a;

        cin >> a;

        if (a >= 0) {

            ans += a;

            dinic.add_edge(0, i + 1, a);

        } else {

            dinic.add_edge(i + 1, n + 1, -a);

        }

    }



    for (int i = 1; i <= n; i++) {

        for (int j = i * 2; j <= n; j += i) {

            dinic.add_edge(j, i, INF);

        }

    }

    

    ans -= dinic.max_flow(0, n + 1);

    cout << ans << "\n";

    return 0;

}