#SP0000224. Kirito vượt mê cung (Kirito in labyrinth)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kirito vượt mê cung (Kirito in labyrinth)
Kirito in labyrinth
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
Kirito travels through a tunnel with rooms numbered to . Room contains monsters. He moves forward only and, at each room, may clear its monsters or skip the room.
A curse applies to every two consecutively chosen rooms: if their monster counts are and , then must hold. Skipped rooms do not influence the condition.
Find the maximum number of rooms Kirito can clear without breaking the curse. Values may repeat. A room containing one monster can only be the sole chosen room.
Input
The first line contains . The second line contains integers giving the monster counts in the rooms.
Output
Print the maximum number of rooms that can be chosen in increasing index order, with gcd greater than for every two consecutively chosen rooms.
Subtasks
-
Subtask 1 (30 points): ; for every .
-
Subtask 2 (70 points): ; for every .
Examples
Input
7
13 2 8 6 3 1 9
Output
5
Explanation
Choose rooms , with monster counts . The adjacent gcd values are , all strictly greater than , so rooms can be cleared. Room with value is coprime to all later room values, while room with value cannot be adjacent to any other selected room. Thus no sequence of rooms exists, and the maximum is .