A15111 | Cute number
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Ran is especially skilled in computation and mathematics. It is said that she can do unimaginable calculation work in an instant.
—Perfect Memento in Strict Sense
Ran Yakumo is a cute girl who loves creating cute Maths problems.
Let $f(x)$ be the minimal [square number](https://en.wikipedia.org/wiki/Square_number) strictly greater than $x$ , and $g(x)$ be the maximal square number not strictly less than $x$ . For example, $f(1)=f(2)=g(4)=g(8)=4$ .
"not strictly less than" means less than or equal to.
A positive integer $x$ is cute if $x-g(x)<f(x)-x$ . For example, $1,5,11$ are cute integers, while $3,8,15$ are not.
Ran gives you an array $a$ of length $n$ . She wants you to find the smallest non-negative integer $k$ such that $a_i + k$ is a cute number for any element of $a$ .
—Perfect Memento in Strict Sense
Ran Yakumo is a cute girl who loves creating cute Maths problems.
Let $f(x)$ be the minimal [square number](https://en.wikipedia.org/wiki/Square_number) strictly greater than $x$ , and $g(x)$ be the maximal square number not strictly less than $x$ . For example, $f(1)=f(2)=g(4)=g(8)=4$ .
"not strictly less than" means less than or equal to.
A positive integer $x$ is cute if $x-g(x)<f(x)-x$ . For example, $1,5,11$ are cute integers, while $3,8,15$ are not.
Ran gives you an array $a$ of length $n$ . She wants you to find the smallest non-negative integer $k$ such that $a_i + k$ is a cute number for any element of $a$ .
输入格式
The first line contains one integer $n$ ( $1 \leq n \leq 10^6$ ) — the length of $a$ .
The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ( $1 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 2\cdot 10^6$ ) — the array $a$ .
The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ( $1 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 2\cdot 10^6$ ) — the array $a$ .
输出格式
Print a single interger $k$ — the answer.
输入输出样例
输入 #1
4 1 3 8 10
输出 #1
1
输入 #2
5 2 3 8 9 11
输出 #2
8
输入 #3
8 1 2 3 4 5 6 7 8
输出 #3
48
Test case 1:
$3$ is not cute integer, so $k\ne 0$ .
$2,4,9,11$ are cute integers, so $k=1$ .
$3$ is not cute integer, so $k\ne 0$ .
$2,4,9,11$ are cute integers, so $k=1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted