#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 105;

struct mf{
	struct edg{ int pos; lint cap; int rev; };
	vector<edg> gph[MAXN];
	void clear(){ for(int i=0; i<MAXN; i++) gph[i].clear(); }
	void add_edge(int s, int e, lint x){
		gph[s].push_back({e, x, (int)gph[e].size()});
		gph[e].push_back({s, 0, (int)gph[s].size()-1});
	}
	int dis[MAXN], pnt[MAXN];
	bool bfs(int src, int sink){
		memset(dis, 0, sizeof(dis));
		memset(pnt, 0, sizeof(pnt));
		queue<int> que;
		que.push(src);
		dis[src] = 1;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(auto &e : gph[x]){
				if(e.cap > 0 && !dis[e.pos]){
					dis[e.pos] = dis[x] + 1;
					que.push(e.pos);
				}
			}
		}
		return dis[sink] > 0;
	}
	lint dfs(int x, int sink, lint f){
		if(x == sink) return f;
		for(; pnt[x] < gph[x].size(); pnt[x]++){
			edg e = gph[x][pnt[x]];
			if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
				lint w = dfs(e.pos, sink, min(f, e.cap));
				if(w){
					gph[x][pnt[x]].cap -= w;
					gph[e.pos][e.rev].cap += w;
					return w;
				}
			}
		}
		return 0;
	}
	lint match(int src, int sink){
		lint ret = 0;
		while(bfs(src, sink)){
			lint r;
			while((r = dfs(src, sink, 1e15))) ret += r;
		}
		return ret;
	}
}mf;

int n, a[MAXN];

int main(){
	cin >> n;
	lint ret = 0;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(a[i] < 0) mf.add_edge(0, i, -a[i]);
		else mf.add_edge(i, n+1, a[i]), ret += a[i];
		for(int j=2*i; j<=n; j+=i) mf.add_edge(i, j, 1e15);
	}
	cout <<ret - mf.match(0, n + 1) << endl;
}
