atcoder#ARC136E. [ARC136E] Non-coprime DAG

[ARC136E] Non-coprime DAG

Score : 800800 points

Problem Statement

We have a directed graph GG with NN vertices numbered 11 to NN.

Between two vertices i,ji,j (1i,jN1 \leq i,j \leq N, iji \neq j), there is an edge iji \to j if and only if both of the following conditions are satisfied.

  • $i
  • gcd(i,j)>1\mathrm{gcd}(i,j)>1

Additionally, each vertex has an associated value: the value of Vertex ii is AiA_i.

Consider choosing a set ss of vertices so that the following condition is satisfied.

  • For every pair (x,y)(x,y) (x)ofdifferentverticesinx) of different vertices in s,, yisunreachablefrom is unreachable from xin in G$.

Find the maximum possible total value of vertices in ss.

Constraints

  • 1N1061 \leq N \leq 10^6
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

6
1 1 1 1 1 1
4

We should choose s={1,2,3,5}s=\{1,2,3,5\}.

6
1 2 1 3 1 6
8

We should choose s={1,5,6}s=\{1,5,6\}.

20
40 39 31 54 27 31 80 3 62 66 15 72 21 38 74 49 15 24 44 3
343