//typedef long double ld;
//template<typename DOUBLE>
//struct Simplex_Steep {
//  using VD = vector<DOUBLE>;
//  using VVD = vector<VD>;
//  using VI = vector<int>;
//  const DOUBLE SIMPLEX_EPS = 1e-12;
//  int m, n;
//  VI B, N;
//  VVD D;
//
//  int iteration_cnt = 0;
//
//  Simplex_Steep(const VVD &A, const VD &b, const VD &c) :
//    m(b.size()), n(c.size()), B(m), N(n+1), D(m+2, VD(n+2)) {
//    for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) D[i][j] = A[i][j];
//    for (int i = 0; i < m; i++) { B[i] = n+i; D[i][n] = -1; D[i][n+1] = b[i]; }
//    for (int j = 0; j < n; j++) { N[j] = j; D[m][j] = -c[j]; }
//    N[n] = -1; D[m+1][n] = 1;
//  }
//
//  void Pivot(int r, int s) {
//    for (int i = 0; i < m+2; i++) if (i != r)
//      for (int j = 0; j < n+2; j++) if (j != s)
//        D[i][j] -= D[r][j] * D[i][s] / D[r][s];
//    for (int j = 0; j < n+2; j++) if (j != s) D[r][j] /= D[r][s];
//    for (int i = 0; i < m+2; i++) if (i != r) D[i][s] /= -D[r][s];
//    D[r][s] = 1.0 / D[r][s];
//    swap(B[r], N[s]);
//  }
//
//  bool Simplex(int phase) {
//    int x = phase == 1 ? m+1 : m;
//    while (true) {
//      ++iteration_cnt;
//      int s = -1;
//      DOUBLE c_val = -1;
//      for (int j = 0; j <= n; j++) {
//        if (phase == 2 && N[j] == -1) continue;
//        DOUBLE norm_sq = 0;
//        for(int k=0; k<=m;++k){ norm_sq+= D[k][j]*D[k][j];}
//        if(norm_sq < SIMPLEX_EPS) norm_sq = SIMPLEX_EPS; // stop division by 0
//        DOUBLE c_val_j = D[x][j] / sqrtl(norm_sq);
//        if (s == -1 || c_val_j < c_val  || (c_val == c_val_j && N[j] < N[s])){
//            s = j; c_val = c_val_j;
//        }
//      }
//      if (D[x][s] >= -SIMPLEX_EPS) return true;
//      int r = -1;
//      for (int i = 0; i < m; i++) {
//        if (D[i][s] <= SIMPLEX_EPS) continue;
//        if (r == -1 || D[i][n+1] / D[i][s] < D[r][n+1] / D[r][s] ||
//            (D[i][n+1] / D[i][s] == D[r][n+1] / D[r][s] && B[i] < B[r])) r = i;
//      }
//      if (r == -1) return false;
//      Pivot(r, s);
//    }
//  }
//
//  DOUBLE solve(VD &x) {
//    int r = 0;
//    for (int i = 1; i < m; i++) if (D[i][n+1] < D[r][n+1]) r = i;
//    if (D[r][n+1] <= -SIMPLEX_EPS) {
//      Pivot(r, n);
//      if (!Simplex(1) || D[m+1][n+1] < -SIMPLEX_EPS) return -numeric_limits<DOUBLE>::infinity();
//      for (int i = 0; i < m; i++) if (B[i] == -1) {
//        int s = -1;
//        for (int j = 0; j <= n; j++)
//          if (s == -1 || D[i][j] < D[i][s] || (D[i][j] == D[i][s] && N[j] < N[s])) s = j;
//        Pivot(i, s);
//      }
//    }
//    if (!Simplex(2)) return numeric_limits<DOUBLE>::infinity();
//    x = VD(n);
//    for (int i = 0; i < m; i++) if (B[i] < n) x[B[i]] = D[i][n+1];
//    return D[m][n+1];
//  }
//};
//void __(){
//    _(int,n);
//    _(vl,a,n);
//    a.insert(a.begin(),0);
//    vvd A;
//    vd B,C,X;
//    rep(i,n+1){
//        C.pb(a[i]);
//        X.pb(0);
//    }
//    rep(i,1,n){
//        vd tmp(n+1);
//        tmp[i] = 1;
//        A.pb(tmp);
//        B.pb(1);
//    }
//    rep(i,1,n){
//        rep(j,i+1,n){
//            if(j%i == 0){
//                vd tmp(n+1);
//                tmp[i] = -1;
//                tmp[j] = 1;
//                A.pb(tmp);
//                B.pb(0);
//            }
//        }
//    }
//    Simplex_Steep<ld> simplex(A,B,C);
//    ld ans = simplex.solve(X);
//    print ll(round(ans));
//}
//
#include <limits>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = (l); i <= (r); ++i)
#define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef vector<vd> vvd;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout) 
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }

    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)

template<typename DOUBLE>
struct Simplex_Steep {
  using VD = vector<DOUBLE>;
  using VVD = vector<VD>;
  using VI = vector<int>;
  const DOUBLE SIMPLEX_EPS = 1e-12;
  int m, n;
  VI B, N;
  VVD D;

  int iteration_cnt = 0;

  Simplex_Steep(const VVD &A, const VD &b, const VD &c) :
    m(b.size()), n(c.size()), B(m), N(n+1), D(m+2, VD(n+2)) {
    for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) D[i][j] = A[i][j];
    for (int i = 0; i < m; i++) { B[i] = n+i; D[i][n] = -1; D[i][n+1] = b[i]; }
    for (int j = 0; j < n; j++) { N[j] = j; D[m][j] = -c[j]; }
    N[n] = -1; D[m+1][n] = 1;
  }

  void Pivot(int r, int s) {
    for (int i = 0; i < m+2; i++) if (i != r)
      for (int j = 0; j < n+2; j++) if (j != s)
        D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < n+2; j++) if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < m+2; i++) if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s];
    swap(B[r], N[s]);
  }

  bool Simplex(int phase) {
    int x = phase == 1 ? m+1 : m;
    while (true) {
      ++iteration_cnt;
      int s = -1;
      DOUBLE c_val = -1;
      for (int j = 0; j <= n; j++) {
        if (phase == 2 && N[j] == -1) continue;
        DOUBLE norm_sq = 0;
        for(int k=0; k<=m;++k){ norm_sq+= D[k][j]*D[k][j];}
        if(norm_sq < SIMPLEX_EPS) norm_sq = SIMPLEX_EPS; // stop division by 0
        DOUBLE c_val_j = D[x][j] / sqrtl(norm_sq);
        if (s == -1 || c_val_j < c_val  || (c_val == c_val_j && N[j] < N[s])){
            s = j; c_val = c_val_j;
        }
      }
      if (D[x][s] >= -SIMPLEX_EPS) return true;
      int r = -1;
      for (int i = 0; i < m; i++) {
        if (D[i][s] <= SIMPLEX_EPS) continue;
        if (r == -1 || D[i][n+1] / D[i][s] < D[r][n+1] / D[r][s] ||
            (D[i][n+1] / D[i][s] == D[r][n+1] / D[r][s] && B[i] < B[r])) r = i;
      }
      if (r == -1) return false;
      Pivot(r, s);
    }
  }

  DOUBLE solve(VD &x) {
    int r = 0;
    for (int i = 1; i < m; i++) if (D[i][n+1] < D[r][n+1]) r = i;
    if (D[r][n+1] <= -SIMPLEX_EPS) {
      Pivot(r, n);
      if (!Simplex(1) || D[m+1][n+1] < -SIMPLEX_EPS) return -numeric_limits<DOUBLE>::infinity();
      for (int i = 0; i < m; i++) if (B[i] == -1) {
        int s = -1;
        for (int j = 0; j <= n; j++)
          if (s == -1 || D[i][j] < D[i][s] || (D[i][j] == D[i][s] && N[j] < N[s])) s = j;
        Pivot(i, s);
      }
    }
    if (!Simplex(2)) return numeric_limits<DOUBLE>::infinity();
    x = VD(n);
    for (int i = 0; i < m; i++) if (B[i] < n) x[B[i]] = D[i][n+1];
    return D[m][n+1];
  }
};
void __(){
    _(int,n);
    _(vl,a,n);
    a.insert(a.begin(),0);
    vvd A;
    vd B,C,X;
    rep(i,n+1){
        C.pb(a[i]);
        X.pb(0);
    }
    rep(i,1,n){
        vd tmp(n+1);
        tmp[i] = 1;
        A.pb(tmp);
        B.pb(1);
    }
    rep(i,1,n){
        rep(j,i+1,n){
            if(j%i == 0){
                vd tmp(n+1);
                tmp[i] = -1;
                tmp[j] = 1;
                A.pb(tmp);
                B.pb(0);
            }
        }
    }
    Simplex_Steep<ld> simplex(A,B,C);
    ld ans = simplex.solve(X);
    print ll(round(ans));
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}



Measured memory_bytes: 1792