Under construction

Still being built. Things may change

Product of Two Numbers 2

Time limit2sMemory limit512 MB

Summary
Given a, b, c, choose positive A, B, C with A*B=C minimizing |A-a|+|B-b|+|C-c|.
Level

Hard8 of 10

Topics
Math, Number theory, Brute force
Solved
No attempts yet

Problem

You are given positive integers aa, bb, and cc. Among all positive integers AA, BB, and CC with A×B=CA \times B = C, find the smallest possible value of ∣A−a∣+∣B−b∣+∣C−c∣|A - a| + |B - b| + |C - c|.

∣x∣|x| is the absolute value of xx.

Input

The first line contains aa, bb, and cc, separated by spaces. (1≤a,b,c≤1091 \le a, b, c \le 10^9)

Output

Print the minimum value of ∣A−a∣+∣B−b∣+∣C−c∣|A - a| + |B - b| + |C - c| on the first line. AA, BB, and CC must all be positive integers with A×B=CA \times B = C.

Examples4

  1. Example 1

    Input
    19 28 522
    
    Expected output
    2
    
  2. Example 2

    Input
    10 30 500
    
    Expected output
    11
    
  3. Example 3

    Input
    111 111 12321
    
    Expected output
    0
    
  4. Example 4

    Input
    1000 100 10
    
    Expected output
    1089