Connection Status:
Competition Arena > CorrectMultiplication
SRM 522 · 2011-05-25 · by lyrically · Brute Force, Simple Math
Class Name: CorrectMultiplication
Return Type: long
Method Name: getMinimum
Arg Types: (int, int, int)
Problem Statement

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 long containing the minimum value of |A - a| + |B - b| + |C - c|, where A, B, and C are positive integers satisfying A * B = C.

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,000, inclusive.
Examples
0)
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.

1)
10
30
500
Returns: 11
2)
11111
11111
123454321
Returns: 0
3)
1000
100
10
Returns: 1089

Note that A, B, and C must be positive integers.

4)
399
522
199999
Returns: 24

Submissions are judged against all 140 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CorrectMultiplication with a public method long long getMinimum(int a, int b, int c) · 140 test cases · 2 s / 256 MB per case

Submitting as anonymous