#SP0000245. Bài toán số học thực sự của Ehab (Ehab’s REAL Number Theory Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán số học thực sự của Ehab (Ehab’s REAL Number Theory Problem)
Ehab's REAL Number Theory Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers. Each has at most seven positive divisors, including and itself.
Choose a non-empty subsequence whose product is a perfect square, minimizing the number of chosen elements. Elements may be skipped, but each input position may be selected at most once. A perfect square is an integer of the form with integral . Output the smallest subsequence length, or -1 if none exists. You do not need to print the subsequence itself.
Input
The first line contains . The second line contains exactly integers .
Output
Print the minimum positive number of selected elements whose product is a perfect square, or -1 if impossible.
Subtasks
-
Subtask 1 (20 points): ; for all ; each has at most seven positive divisors.
-
Subtask 2 (30 points): ; for all ; each has at most seven positive divisors.
-
Subtask 3 (50 points): ; for all ; each has at most seven positive divisors.
Examples
Input
3
6 15 10
Output
3
Explanation
For , none of the individual entries is a square. No pair gives a square: , , and . Selecting all three yields . Thus the shortest valid non-empty subsequence has length , so print 3.