#6148. [EC Final 2019] Value

[EC Final 2019] Value

[EC Final 2019] Value

题目描述

$\textit{Pang}$ believes that one cannot make an omelet without breaking eggs.

For a subset AA of {1,2,…,n}\{1,2,\ldots,n\}, we calculate the score of AA as follows:

  • Initialize the score as 00.
  • For any i∈Ai\in A, add aia_i to the score.
  • For any pair of integers (i,j)(i, j) satisfying i≥2i\ge 2, j≥2j\ge 2, i∈Ai\in A and j∈Aj\in A, if there exists positive integer k>1k > 1 such that ik=ji^k=j, subtract bjb_j from the score.

Find the maximum possible score over the choice of AA.

输入格式

The first line contains a single integer $n$ $(1\le n\le 100000)$.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1000000000)(1\le a_i\le 1000000000).

The third line contains nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n (1≤bi≤1000000000)(1\le b_i\le 1000000000).

输出格式

Print a single integer $x$ --- the maximum possible score.
4
1 1 1 2
1 1 1 1
4
4
1 1 1 1
1 1 1 2
3

提示

(暂无提示) 标签: P13950|2019|ICPC|EC Final

来源

P13950|[EC Final 2019] Value