#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=105,INF=1e9 + 5;
struct Edge{
    int from,to,cap,flow;
    Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){}
};
struct ISAP{
    int n,s,t;
    vector<Edge> edges;
    vector<int> G[maxn];
    bool vis[maxn];
    int d[maxn];
    int cur[maxn];
    int p[maxn];
    int num[maxn];

    void init(int n){
        this->n=n;
        edges.clear();
        for(int i=0;i<n;i++)G[i].clear();
    }

    void AddEdge(int from,int to,int cap){
        edges.push_back(Edge(from,to,cap,0));
        edges.push_back(Edge(to,from,0,0));
        G[from].push_back(edges.size()-2);
        G[to].push_back(edges.size()-1);
    }

    void BFS(){
        memset(vis,0,sizeof(vis));
        queue<int> Q;
        Q.push(t);
        d[t]=0;
        vis[t]=1;
        while(!Q.empty()){
            int x=Q.front();Q.pop();
            for(int i=0;i<G[x].size();i++){
                Edge &e=edges[G[x][i]^1];
                if(e.flow==e.cap)continue;
                if(!vis[e.from]){
                    vis[e.from]=1;
                    d[e.from]=d[x]+1;
                    Q.push(e.from);
                }
            }
        }
    }

    int Augment(){
        int x=t,a=INF;
        while(x!=s){
            Edge &e=edges[p[x]];
            a=min(a,e.cap-e.flow);
            x=edges[p[x]].from;
        }
        x=t;
        while(x!=s){
            edges[p[x]].flow+=a;
            edges[p[x]^1].flow-=a;
            x=edges[p[x]].from;
        }
        return a;
    }

    ll Maxflow(int s,int t){
        this->s=s;this->t=t;
        ll flow=0;
        BFS();
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)num[d[i]]++;
        int x=s;
        memset(cur,0,sizeof(cur));
        while(d[s]<n){
            if(x==t){
                flow+=Augment();
                x=s;
            }
            int ok=0;
            for(int i=cur[x];i<G[x].size();i++){
                Edge &e=edges[G[x][i]];
                if(e.cap>e.flow&&d[x]==d[e.to]+1){
                    ok=1;
                    p[e.to]=G[x][i];
                    cur[x]=i;
                    x=e.to;
                    break;
                }
            }
            if(!ok){
                int m=n-1;
                for(int i=0;i<G[x].size();i++){
                    Edge &e=edges[G[x][i]];
                    if(e.cap>e.flow)m=min(m,d[e.to]);
                }
                if(--num[d[x]]==0)break;
                num[d[x]=m+1]++;
                cur[x]=0;
                if(x!=s)x=edges[p[x]].from;
            }
        }
        return flow;
    }
}isap;

int p[100], len = 0;
void CalP(){
    p[len++] = 1;
    int Is_p[100];
    memset(Is_p, -1, sizeof(Is_p));
    for(int i = 2; i < 100; i++){
        if(Is_p[i] == 0)continue;
        p[len++] = i;
        for(int j = 2; j * i < 100; j++){
            Is_p[j * i] = false;
        }
    }
}
int n;
ll a[maxn];
int main(){
//    freopen("e:\\in.txt","r",stdin);
//    CalP();
    cin>>n;
    isap.init(n + 2);
    ll sum = 0;
    int s = 0, t = n + 1;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        if(a[i] > 0)sum += a[i];
        a[i] = -a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 2; j * i <= n; j++)
            isap.AddEdge(i, i * j, INF);
    }
    for(int i = 1; i <=n; i++){
        if(a[i] > 0)isap.AddEdge(s, i, a[i]);
        else if(a[i] < 0)isap.AddEdge(i, t, -a[i]);
    }
    cout<<sum - isap.Maxflow(s, t)<<endl;
    return 0;
}


Measured memory_bytes: 256