#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

struct edge{ll to,cap,rev;};

const int MAX_V=222;
const ll INF=LLONG_MAX/2;
vector<edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from,int to,ll cost){
  G[from].push_back((edge){to,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

ll dfs(int v,int t,ll f){
  if(v==t) return f;
  used[v]=1;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
	     ll d=dfs(e.to,t,min(f,e.cap));
	      if(d>0){
	         e.cap-=d;
	         G[e.to][e.rev].cap+=d;
	         return d;
	      }
	  }
  }
  return 0;
}

ll max_flow(int s,int t){
  ll flow=0;
  while(1){
    memset(used,0,sizeof(used));
    ll f=dfs(s,t,INF);
    if(f==0) return flow;
    flow+=f;
  }
}


int main(){
  int N; cin>>N;
  ll A[N+1], sum=0;
  for(int i=1;i<=N;i++){
    cin>>A[i];
    if(A[i]>=0){
      sum+=A[i];
      add_edge(i,N+1,A[i]);
    }else{
      add_edge(0,i,-A[i]);
    }
  }
  for(int i=1;i<=N;i++){
    for(int j=2*i;j<=N;j+=i) add_edge(i,j,INF);
  }
  cout<<sum-max_flow(0,N+1)<<endl;
  return 0;
}
