#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "CONTINUE"
#define FALSE__ "GAMEOVER"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define fcout cout << fixed << setprecision(12)

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

namespace mylib {
//	using ll = long long;
struct Dinic {
	// O(|E||V|^2)
	struct edge {
		int to;
		ll c;
		int rev;
		edge(int x, ll y, int z) : to(x), c(y), rev(z) {}
	};
	vector<vector<edge>> v;
	vector<int> level;
	vector<int> iter;
	int N;
	const ll INF = LLONG_MAX;
	Dinic(int a) {
// N:Vertex(|V|)
		N = a;
		level.RS(N);
		iter.RS(N);
		v.RS(N);
	}
	void add_edge(int x, int y, ll z) {
// x:from y:to z:capacity
		v[x].PB(edge(y, z, v[y].size()));
		v[y].PB(edge(x, 0, v[x].size()-1));
	}
	ll dfs(int s, int t, ll f) {
		if (s == t) return f;
		for (int& i = iter[s]; i < (int) v[s].size(); i++) {
			auto& x = v[s][i];
			if (x.c == 0 || level[s] >= level[x.to]) continue;
			int d;
			if ((d = dfs(x.to, t, min(f, x.c))) > 0) {
				x.c -= d;
				v[x.to][x.rev].c += d;
				return d;
			}
		}
		return 0;
	}
	void bfs(int s) {
		fill(all(level), -1);
		queue<pair<int, int>> q;
		q.push(MP(s, 0));
		while (!q.empty()) {
			auto x = q.front();
			q.pop();
			int a = x.first;
			int b = x.second;
			if (level[a] != -1) continue;
			level[a] = b;
			for (auto y : v[a]) {
				if (y.c > 0) q.push(MP(y.to, b+1));
			}
		}
	}
	ll calc(int s, int t) {
		ll res = 0;
		while (true){
			bfs(s);
			if (level[t] < 0) return res;
			fill(all(iter), 0);
			ll r;
			do {
				r = dfs(s, t, INF);
				res += r;
			} while (r);
		}
	}
};
}

int N;

using namespace mylib;

void init()
{
	cin >> N;
	Dinic Di(N+2);
	reps(i, 1, N) {
		for (int j = i*2; j <= N; j += i) {
			Di.add_edge(i-1, j-1, LLONG_MAX);
		}
	}
	int s = N;
	int t = s+1;
	ll res = 0;
	rep(i, N) {
		int x;
		cin >> x;
		res += max(x, 0LL);
		if (x < 0) {
			Di.add_edge(s, i, -x);
		} else if (x > 0) {
			Di.add_edge(i, t, x);
		}
	}
	cout << res - Di.calc(s, t) << endl;
}

void solve()
{
}





Measured memory_bytes: 256