PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000132. Chia cho 2 hoặc 3 (Divide by 2 or 3)
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 cho 2 hoặc 3 (Divide by 2 or 3)
Divide by 2 or 3
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers, each operation divides a chosen array element by 2 if divisible by 2, or by 3 if divisible by 3. Determine the minimum number of operations required to make all elements equal, or print -1 if impossible.
Input
The first line contains ; the second contains integers .
Output
Print the minimum number of operations or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
1 4 3
Output
3
Explanation
Changing 4 to 1 takes two divisions by 2; changing 3 to 1 takes one division by 3. The array becomes [1,1,1] in three necessary operations.