import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

immutable long INF = 1L << 60;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    A = 0 ~ A;

    if (A.map!(a => a <= 0).all) {
        writeln(0);
        return;
    }

    auto ng = new bool[](N+1);


    for (int i = N; i > 1; --i) {
        long tmp = 0;
        for (int j = i; j <=N; j += i) {
            tmp += ng[j] ? 0 : A[j];
        }
        if (tmp < 0)
            ng[i] = true;
    }


    auto ok = new bool[](N+1);
    ok.fill(true);

    foreach (i; 2..N+1)
        if (ng[i])
            for (int j = i; j <= N; j += i)
                ok[j] = false;

    long ans = 0;
    foreach (i; 1..N+1)
        if (ok[i])
            ans += A[i];

    ans.writeln;
}
