Under construction

Still being built. Things may change

Product of Two Numbers

Time limit2sMemory limit512 MB

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

Medium7 of 10

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

Problem

You are given three integers aa, bb, cc. Among all positive integers AA, BB, 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, cc separated by spaces. (1≤a,b,c≤1061 \le a, b, c \le 10^6)

Output

Print the minimum value of ∣A−a∣+∣B−b∣+∣C−c∣|A - a| + |B - b| + |C - c| on the first line. A×BA \times B must equal CC.

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