PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000163. Chia dãy thành ít đoạn không có tích chính phương (Square-Free Division (easy version))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia dãy thành ít đoạn không có tích chính phương (Square-Free Division (easy version))
Square-Free Division (easy version)
Source: Codeforces 1497E1
Version: Phuoc Hung OJ Extended — one dataset per judge run.
Problem Statement
Partition the array into as few contiguous segments as possible so that no two distinct positions in a segment have a product that is a perfect square. This is the easy version: , so no value may be changed.
Input
The first line contains and . The second line contains integers .
Output
Print the minimum number of segments.
Subtasks
- Subtask 1 (20 points): , , .
- Subtask 2 (30 points): , , .
- Subtask 3 (50 points): , , .
Example
Input
5 0
18 6 2 4 1
Output
3
Explanation
An optimal partition is , , : no segment contains two equal square-free kernels.