PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000354. Biến đổi số bằng thừa số nguyên tố (Number Transformation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 ss (start) and tt (target). From state xx, select a prime factor pp of xx satisfying 1<p<x1<p<x and move to x+px+p.

You may not add xx itself, even if xx is prime; 1 has no valid prime factor. Every move strictly increases the state, so a state above tt cannot reach the target again.

Find the minimum number of moves to reach tt starting at ss, or output -1 if impossible. If s=ts=t, the answer is 0.

PHOJ adaptation: Each file contains one pair s,ts,t; do not print the Case k: prefix of the original LightOJ format.

Input

One line containing s,ts,t.

Output

The minimum number of moves, or -1.

Subtasks

  • Subtask 1 (20 points): 1<=s<=100,1<=t<=1001 <= s <= 100, 1 <= t <= 100.
  • Subtask 2 (30 points): 1<=s<=100,1<=t<=5001 <= s <= 100, 1 <= t <= 500.
  • Subtask 3 (50 points): 1<=s<=100,1<=t<=10001 <= s <= 100, 1 <= t <= 1000.

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.