import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int[] a = [0] ~ readln.chomp.split.map!(to!int).array;
  bool[] done = new bool[](n + 1);
  int ans = a.sum;
  for (int i = n; 0 < i; --i) {
    // 試し割り
    int sub = ans;
    for (int j = i; j <= n; j += i) {
      if (done[j]) {
        continue;
      }
      sub -= a[j];
    }
    if (sub > ans) {
      // 採用
      for (int j = i; j <= n; j += i) {
        if (done[j]) {
          continue;
        }
        done[j] = true;
        ans -= a[j];
      }
    }
  }
  ans.writeln;
}
