A12060 | Recovering BST
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset.
To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed $1$ .
Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found [here.](https://en.wikipedia.org/wiki/Binary_search_tree)
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset.
To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed $1$ .
Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found [here.](https://en.wikipedia.org/wiki/Binary_search_tree)
输入格式
The first line contains the number of vertices $n$ ( $2 \le n \le 700$ ).
The second line features $n$ distinct integers $a_i$ ( $2 \le a_i \le 10^9$ ) — the values of vertices in ascending order.
The second line features $n$ distinct integers $a_i$ ( $2 \le a_i \le 10^9$ ) — the values of vertices in ascending order.
输出格式
If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than $1$ , print "Yes" (quotes for clarity).
Otherwise, print "No" (quotes for clarity).
Otherwise, print "No" (quotes for clarity).
输入输出样例
输入 #1
6 3 6 9 18 36 108
输出 #1
Yes
输入 #2
2 7 17
输出 #2
No
输入 #3
9 4 8 10 12 15 18 33 44 81
输出 #3
Yes
The picture below illustrates one of the possible trees for the first example.
The picture below illustrates one of the possible trees for the third example.

The picture below illustrates one of the possible trees for the third example.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted