#SP0000234. Chia dãy không có tích chính phương (bản khó) (Square-Free Division (hard version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia dãy không có tích chính phương (bản khó) (Square-Free Division (hard version))
Square-Free Division (hard version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers . Before splitting it, you may perform at most changes. In each change, choose an array position and replace its value with any positive integer.
Then partition the entire array into nonempty, consecutive, nonoverlapping segments. Within any segment, there must not be two distinct positions whose values multiply to a perfect square. A perfect square is the square of a nonnegative integer.
Find the minimum possible number of segments after choosing the changes optimally. Equal values at different positions still represent distinct positions.
Input
Line 1 contains . Line 2 contains exactly positive integers .
Output
Print one integer: the minimum number of consecutive segments after at most changes.
Subtasks
-
Subtask 1 (20 points): ; ; for all .
-
Subtask 2 (30 points): ; ; for all .
-
Subtask 3 (50 points): ; ; for all .
Examples
Input
5 2
18 6 2 4 1
Output
1
Explanation
Here and . Change position from to , and position from to , obtaining . No product of values at two different positions is a perfect square (for example, , , and are not squares; the remaining pairs also pass). Thus the entire array forms one valid segment. A nonempty array cannot use fewer than one segment, so the answer is .