#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
struct Ford_Fulkerson {

	struct f_edge {
		ll to;
		ll cap;
		ll fl;
		ll rev;//反対方向の辺の添え字
	};


	ll N;
	ll s, t;
	vector<vector<edge>> g;//グラフ片方向にのみ張る、flowで双方向に構築
	vector<vector<f_edge>> flow;
	ll maxflow;

	vector<bool> see;
	ll dfs(ll v, ll x) {
		see[v] = 1;

		if (v == t) { return x; }

		rep(i, flow[v].size()) {
			const auto e = flow[v][i];

			if (see[e.to] == 1) { continue; }
			if (e.cap == e.fl) { continue; }

			ll y = min(x, e.cap - e.fl);

			y = dfs(e.to, y);
			if (y == 0) { continue; }

			flow[v][i].fl += y;
			flow[e.to][e.rev].fl -= y;
			return y;
		}

		return 0;
	}

	Ford_Fulkerson(ll N0, vector<vector<edge>> g0, ll s0, ll t0) {
		N = N0;
		g = g0;
		s = s0;
		t = t0;

		flow.resize(N + 1);
		repn(v, N) {
			for (edge e : g[v]) {
				ll w = e.to;
				flow[v].push_back({ w,e.d,0,flow[w].size() });
				flow[w].push_back({ v,0,0,flow[v].size() - 1 });
			}
		}

		maxflow = 0;

		if (s == t) { maxflow = INF; return; }

		while (1) {
			see.assign(N + 1, 0);
			ll f = dfs(s, INF);
			if (f == 0) { break; }
			maxflow += f;
		}

		maxflow = min(INF, maxflow);

		return;

	}
};

int main() {
	ll M = 1e9;
	ll L = 1e12;

	ll N;
	cin >> N;
	vll a(N + 1);

	repn(i, N) { cin >> a[i]; }

	vector<vector<edge>> g(N + 3);
	repn(i, N) {
		g[N + 1].push_back({ 0,N + 1,i,M + a[i] });
		g[i].push_back({ 0,i,N + 2,M });
	}

	repn(i, N) {
		for (ll j = 2 * i; j <= N; j += i) {
			g[j].push_back({ 0,j,i,M+L});
		}
	}

	Ford_Fulkerson fd(N + 2, g, N + 1, N + 2);

	ll f = fd.maxflow;
	f -= M * N;

	//cout << f << endl;

	

	ll S = 0;
	repn(i, N) S += a[i];

	ll ans = S - f;
	cout << ans << endl;
}

Measured memory_bytes: 384