5111.Recovering BST

传统题 时间 1000 ms 内存 256 MiB 尝试 0 已通过 0 标签

Recovering BST

CF1025D · Recovering BST

  • 难度:2100
  • 标签:brute force、dp、math、number theory、trees
  • 链接:https://codeforces.com/problemset/problem/1025/D
  • 时间限制:1 second 内存限制:256 megabytes
  • 出现位置:Day17-树形DP-区间DP-计数DP;Day30-结营-个人错题重做-公共重测池-尖子拔高

英文原题面

Statement

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 11. 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.

Input

The first line contains the number of vertices nn (2n7002 \le n \le 700). The second line features nn distinct integers aia_i (2ai1092 \le a_i \le 10^9) — the values of vertices in ascending order.

Output

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 11, print "Yes" (quotes for clarity). Otherwise, print "No" (quotes for clarity).

样例

样例 1

输入:

6
3 6 9 18 36 108

输出:

Yes

样例 2

输入:

2
7 17

输出:

No

样例 3

输入:

9
4 8 10 12 15 18 33 44 81

输出:

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.

在线编程 IDE

建议全屏模式获得最佳体验