CorrectMultiplicationTwo
SRM 522 · 2011-05-25 · by lyrically
SRM 522 · 2011-05-25 · by lyrically · Brute Force, Simple Math
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 threeint s 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.
You are given three
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
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)
111 111 12321 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 123 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class CorrectMultiplicationTwo with a public method int getMinimum(int a, int b, int c) · 123 test cases · 2 s / 256 MB per case