#abc276d. D - Divide by 2 or 3
D - Divide by 2 or 3
Score : points
问题描述
给定一个正整数序列:。
你可以任意次数(包括零次)选择并执行以下操作之一:
- 选择一个满足 且 是2的倍数的整数 ,并将 替换为 。
- 选择一个满足 且 是3的倍数的整数 ,并将 替换为 。
你的目标是使序列 满足 。
找出实现目标所需的最小操作总次数。如果无法实现目标,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3
1 4 3
Sample Output 1
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 .
Sample Input 2
3
2 7 6
Sample Output 2
-1
There is no way to achieve the objective.
Sample Input 3
6
1 1 1 1 1 1
Sample Output 3
0
update @ 2024/3/10 11:37:21