atcoder#ABC276D. [ABC276D] Divide by 2 or 3
[ABC276D] Divide by 2 or 3
Score : points
Problem Statement
You are given a sequence of positive integers: . You can choose and perform one of the following operations any number of times, possibly zero.
- Choose an integer such that and is a multiple of , and replace with .
- Choose an integer such that and is a multiple of , and replace with .
Your objective is to make satisfy .
Find the minimum total number of times you need to perform an operation to achieve the objective. If there is no way to achieve the objective, print -1
instead.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
3
1 4 3
3
Here is a way to achieve the objective in three operations, which is the minimum needed.
- Choose an integer such that is a multiple of , and replace with . becomes .
- Choose an integer such that is a multiple of , and replace with . becomes .
- Choose an integer such that is a multiple of , and replace with . becomes .
3
2 7 6
-1
There is no way to achieve the objective.
6
1 1 1 1 1 1
0