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

#SP0000276. Phép nhân chia nhỏ nhất (Small Operations)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 xx, yy, and kk. Initially, your number is xx. In each operation, choose an integer aa with 1≤a≤k1\le a\le k, then either multiply the current number by aa or divide it by aa, provided the quotient is an integer. You may reuse any value of aa. Find the minimum number of operations to reach yy; print -1 if it is impossible.

Input

One line contains the positive integers xx, yy, and kk, in this order.

Output

Print the minimum number of operations, or -1 if reaching yy from xx is impossible.

Subtasks

  • Subtask 1 (20 points): 1≤x,y,k≤201\le x,y,k\le 20.
  • Subtask 2 (30 points): 1≤x,y,k≤20001\le x,y,k\le 2000.
  • Subtask 3 (50 points): 1≤x,y,k≤10000001\le x,y,k\le 1000000.

Examples

Example 1

Input

4 6 3

Output

2

Explanation

Start at 44. Divide by 22 to reach 22 (operation 1), then multiply by 33 to reach 66 (operation 2). Neither 6/46/4 nor 4/64/6 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 4=224=2^2 has no factor 55. Multiplication or division by an integer a≤3a\le3 can only add or remove factors 22 and 33, never a factor 55. Thus 55 cannot be reached, and the answer is -1.

Example 3

Input

10 45 3

Output

3

Explanation

Perform 10→510\to5 by dividing by 22, then 5→155\to15 and 15→4515\to45 by multiplying by 33 twice. This uses 33 operations. At least one operation must remove the factor 22, and the two factors 33 cannot be introduced in a single operation since 9>k=39>k=3. Therefore fewer than 33 operations are impossible.

Example 4

Input

1 982800 13

Output

6

Explanation

Factor 982800=24⋅33⋅52⋅7⋅13982800=2^4\cdot3^3\cdot5^2\cdot7\cdot13. Group it as 9⋅12⋅10⋅10⋅7⋅139\cdot12\cdot10\cdot10\cdot7\cdot13. From 11, multiply successively by 9,12,10,10,7,139,12,10,10,7,13 to obtain 1→9→108→1080→10800→75600→9828001\to9\to108\to1080\to10800\to75600\to982800. Each multiplier is at most 1313, so six operations suffice. The prime factors 77 and 1313 each require their own operation. The remaining product is 10800>13310800>13^3, so it cannot be formed in just three additional operations. Hence five operations cannot suffice, and the minimum is 6.