#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const long long INF = (1LL << 60);
long long cap[102][102];

long long search(int n, const vector<int>& level, vector<int>& itr, int cur, int t, long long f){
	if(cur == t) return f;
	for(int i=itr[cur];i<n;i++){
		if(cap[cur][i] > 0 && level[cur] < level[i]){
			long long d = search(n, level, itr, i, t, min(cap[cur][i], f));
			if(d > 0){
				itr[cur] = i;
				cap[cur][i] -= d;
				cap[i][cur] += d;
				return d;
			}
		}
	}
	itr[cur] = n;
	return 0;
}

long long maximumFlow(int n, int s, int t){
	long long res = 0;
	while(true){
		queue<int> qu; qu.push(s);
		vector<int> level(n, -1); level[s] = 0;
		vector<int> itr(n, 0);
		while(!qu.empty()){
			int cur = qu.front(); qu.pop();
			for(int i=0;i<n;i++){
				if(cap[cur][i] > 0 && level[i] == -1){
					level[i] = level[cur]+1;
					qu.push(i);
				}
			}
		}
		if(level[t] == -1) break;
		for(long long f;(f=search(n, level, itr, s, t, INF)) > 0;res+=f);
	}
	return res;
}

int main(){
	int N;
	while(cin >> N){
		for(int i=0;i<=N+1;i++){
			for(int j=0;j<=N+1;j++) cap[i][j] = 0;
		}
		long long sum = 0;
		for(int i=1;i<=N;i++){
			int a; cin >> a;
			sum += max(0, a);
			if(a < 0){
				cap[0][i] = -a;
			} else {
				cap[i][N+1] = a;
			}
		}
		for(int i=1;i<=N;i++){
			for(int j=2*i;j<=N;j+=i) cap[i][j] = INF;
		}
		cout << sum - maximumFlow(N+2, 0, N+1) << endl;
	}
}
