#SP0000276. Phép nhân chia nhỏ nhất (Small Operations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phép nhân chia nhỏ nhất (Small Operations)
Small Operations
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers , , and . Initially, your number is . In each operation, choose an integer with , then either multiply the current number by or divide it by , provided the quotient is an integer. You may reuse any value of . Find the minimum number of operations to reach ; print -1 if it is impossible.
Input
One line contains the positive integers , , and , in this order.
Output
Print the minimum number of operations, or -1 if reaching from is impossible.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
4 6 3
Output
2
Explanation
Start at . Divide by to reach (operation 1), then multiply by to reach (operation 2). Neither nor is an integer, so a single operation cannot work. The answer is 2.
Example 2
Input
4 5 3
Output
-1
Explanation
The starting value has no factor . Multiplication or division by an integer can only add or remove factors and , never a factor . Thus cannot be reached, and the answer is -1.
Example 3
Input
10 45 3
Output
3
Explanation
Perform by dividing by , then and by multiplying by twice. This uses operations. At least one operation must remove the factor , and the two factors cannot be introduced in a single operation since . Therefore fewer than operations are impossible.
Example 4
Input
1 982800 13
Output
6
Explanation
Factor . Group it as . From , multiply successively by to obtain . Each multiplier is at most , so six operations suffice. The prime factors and each require their own operation. The remaining product is , so it cannot be formed in just three additional operations. Hence five operations cannot suffice, and the minimum is 6.