A10437 | Ultimate Weirdness of an Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ !
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$ !
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=200000$ ) — the number of elements in $a$ .
The next line contains $n$ integers $a_{i}$ ( $1<=a_{i}<=200000$ ), 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.
The next line contains $n$ integers $a_{i}$ ( $1<=a_{i}<=200000$ ), 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.
输出格式
Print a single line containing the value of ultimate weirdness of the array $a$ .
输入输出样例
输入 #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)$ 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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted