#GL0000354. Biến đổi số bằng thừa số nguyên tố (Number Transformation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Biến đổi số bằng thừa số nguyên tố (Number Transformation)
Number Transformation
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers (start) and (target). From state , select a prime factor of satisfying and move to .
You may not add itself, even if is prime; 1 has no valid prime factor. Every move strictly increases the state, so a state above cannot reach the target again.
Find the minimum number of moves to reach starting at , or output -1 if impossible. If , the answer is 0.
PHOJ adaptation: Each file contains one pair ; do not print the Case k: prefix of the original LightOJ format.
Input
One line containing .
Output
The minimum number of moves, or -1.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
6 12
Output
2
Explanation
3 is a proper prime factor of both 6 and 9. The route 6 → 9 → 12 takes two moves; one move cannot reach 12.
Example 2
Input
6 13
Output
-1
Explanation
From 6 one can reach 8 or 9; neither can eventually reach 13 using allowed moves.
Example 3
Input
4 4
Output
0
Explanation
The start already equals the target, so zero moves suffice.