TopcoderArchiveVisit Topcoder
SRM25 May 2011
SRM 522

CorrectMultiplicationTwo

Problem statement, definition, constraints, and public examples.

Problem Statement

Krolik found a sheet of paper with an equation containing three positive integers: "a * b = c". This equation might be wrong, so Krolik is trying to make it correct by adjusting the numbers a, b, and c.

You are given three ints a, b, and c. Return a int containing the minimum value of |A - a| + |B - b| + |C - c|, where A, B, and C are positive integers satisfying A * B = C.

Definition

Class:
CorrectMultiplicationTwo
Method:
getMinimum
Parameters:
int, int, int
Returns:
int
Method signature:
int getMinimum(int a, int b, int c)
(be sure your method is public)

Notes

  • |x| is the absolute value of x (which is x for non-negative x and (-x) for negative x).

Constraints

  • a, b, and c will each be between 1 and 1,000,000, inclusive.

Examples

  1. 19
    28
    522
    Returns: 2
    By assigning A = 18, B = 29, and C = 522 the value of |A - a| + |B - b| + |C - c| is minimized.
  2. 10
    30
    500
    Returns: 11
  3. 111
    111
    12321
    Returns: 0
  4. 1000
    100
    10
    Returns: 1089
    Note that A, B, and C must be positive integers.
  5. 399
    522
    199999
    Returns: 24
Back to all problems