CF671C.Ultimate Weirdness of an Array

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yasin has an array a containing n integers. Yasin is a 5 year old, so he loves ultimate weird things.

Yasin denotes weirdness of an array as maximum gcd(a__i,  a__j) value among all 1 ≤ i < j ≤ n. For n ≤ 1 weirdness is equal to 0, gcd(x,  y) is the greatest common divisor of integers x and y.

He also defines the ultimate weirdness of an array. Ultimate weirdness is where f(i,  j) is weirdness of the new array a obtained by removing all elements between i and j inclusive, so new array is [_a_1... a__i - 1, a__j + 1... a__n].

Since 5 year old boys can't code, Yasin asks for your help to find the value of ultimate weirdness of the given array a!

亚辛有一个包含 nn 个整数的数组 aa。亚辛今年 5 岁,因此他酷爱极致古怪的事物。

亚辛将一个数组的“古怪度”(weirdness)定义为所有满足 1≤i<j≤n1 \leq i < j \leq n 的下标对 (i,j)(i, j) 中 gcd⁡(ai, aj)\gcd(a_i,\, a_j) 的最大值。当 n≤1n \leq 1 时,古怪度定义为 00;其中 gcd⁡(x, y)\gcd(x,\, y) 表示整数 xx 和 yy 的最大公约数。

他还定义了数组的“极致古怪度”(ultimate weirdness)。极致古怪度为
,
其中 f(i, j)f(i,\, j) 表示将原数组 aa 中下标在区间 [i,j][i, j] 内(含端点)的所有元素全部删除后所得新数组的古怪度;即新数组为 [a1, …, ai−1, aj+1, …, an][a_1,\, \dots,\, a_{i-1},\, a_{j+1},\, \dots,\, a_n]。

由于 5 岁的小男孩还不会编程,亚辛请求你帮忙计算给定数组 aa 的极致古怪度!

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in a.

The next line contains n integers a__i (1 ≤ a__i ≤ 200 000), where the i-th number is equal to the i-th element of the array a. It is guaranteed that all a__i are distinct.

输入的第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000)—— 表示数组 aa 的元素个数。

下一行包含 nn 个整数 aia_i(1≤ai≤200 0001 \leq a_i \leq 200\,000),其中第 ii 个数等于数组 aa 的第 ii 个元素。保证所有 aia_i 互不相同。

输出格式

Print a single line containing the value of ultimate weirdness of the array a.

输出一行,包含数组 aa 的“终极怪异值”。

输入输出样例

  • 输入#1

    3
    2 6 3

    输出#1

    6

说明/提示

Consider the first sample.

  • f(1,  1) is equal to 3.
  • f(2,  2) is equal to 1.
  • f(3,  3) is equal to 2.
  • f(1,  2), f(1,  3) and f(2,  3) are equal to 0.

Thus the answer is 3 + 0 + 0 + 1 + 0 + 2 = 6.

考虑第一个样例。

  • f(1, 1)f(1,\ 1) 等于 3。
  • f(2, 2)f(2,\ 2) 等于 1。
  • f(3, 3)f(3,\ 3) 等于 2。
  • f(1, 2)f(1,\ 2)、f(1, 3)f(1,\ 3) 和 f(2, 3)f(2,\ 3) 均等于 0。

因此答案为 3 + 0 + 0 + 1 + 0 + 2 = 63\ +\ 0\ +\ 0\ +\ 1\ +\ 0\ +\ 2\ =\ 6。

输入解题思路,AI测评打分。不知道怎么写?

首页