#include <bits/stdc++.h>

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

using namespace std;


// 最大流問題を解く　O(|E||V|^2)
class Dinic {

    struct edge {
        unsigned int to;    // 行き先
        unsigned int rev;   // 逆辺
        long long cap;      // 容量
    };

    vector<vector<edge>> graph; // グラフの隣接リスト表現
    vector<int> level;          // sからの距離
    vector<unsigned int> iter;  // どこまで調べ終わったか

public:

    Dinic(unsigned int num_of_node) {
        assert(num_of_node > 0);
        graph.resize(num_of_node);
        level.resize(num_of_node);
        iter.resize(num_of_node);

    }

    // fromからtoへ向かう容量capの辺をグラフに追加する
    void add_edge(unsigned int from, unsigned int to, long long cap) {
        graph[from].push_back((edge) {to, (unsigned int)graph[to].size(),       cap});
        graph[to].push_back((edge) {from, (unsigned int)graph[from].size() - 1, 0});
    }

    // sからtへの最大流を求める
    long long max_flow(unsigned int s, unsigned int t) {
        long long flow = 0;
        while (true) {
            bfs(s);
            if (level.at(t) < 0) {
                return flow;
            }
            fill(iter.begin(), iter.end(), 0);
            long long f;
            while ((f = dfs(s, t, INT_MAX)) > 0) {
                flow += f;
            }
        }
    }

private:
    // sからの最短距離をBFSで計算する
    void bfs(unsigned int s) {
        fill(level.begin(), level.end(), -1);
        queue<unsigned int> que;
        level.at(s) = 0;
        que.push(s);
        while (not que.empty()) {
            unsigned int v = que.front();
            que.pop();
            for (int i = 0; i < graph.at(v).size(); ++i) {
                edge &e = graph.at(v).at(i);
                if (e.cap > 0 && level.at(e.to) < 0) {
                    level.at(e.to) = level.at(v) + 1;
                    que.push(e.to);
                }
            }
        }
    }

    // 増加パスをDFSで探す
    long long dfs(unsigned int v, unsigned int t, long long f) {
        if (v == t) {
            return f;
        }
        for (unsigned int &i = iter.at(v); i < graph.at(v).size(); ++i) {
            edge &e = graph.at(v).at(i);
            if (e.cap > 0 && level.at(v) < level.at(e.to)) {
                long long d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    graph.at(e.to).at(e.rev).cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};


void solve(unsigned int N, vector<LL> A) {
    Dinic dinic(N + 2);
    int source = N;
    int sink = source + 1;

    LL total = 0;
    FOR(i, 0, A.size()) {
        if (A[i] < 0) {
            dinic.add_edge(source, i, -A[i]);
        } else {
            total += A[i];
            dinic.add_edge(i, sink, A[i]);
        }
    }

    FOR(i, 0, A.size()) {
        int node1 = i + 1;
        for (int node2 = node1 * 2; node2 <= A.size(); node2 += node1) {
            dinic.add_edge(node1 - 1, node2 - 1, INT_MAX);
        }
    }

    cout << total - dinic.max_flow(source, sink) << endl;


}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    unsigned int N;
    cin >> N;
    vector<LL> A(N);
    FOR(i, 0, N) {
        cin >> A[i];
    }

    solve(N, A);

    return 0;
}



Measured memory_bytes: 256