Given three integers a, b and x, the task is to get the multiple of x which is closest to ab.
Input: a = 5, b = 4, x = 3
54 = 625 and 624 is the multiple of 3 which is closest to 625
Input: a = 349, b = 1, x = 4
- Calculate ab and store it in a variable say num.
- Then, calculate ⌊num / x⌋ and store it in a variable floor.
- Now the closest element at the left will be closestLeft = x * floor.
- And the closest element on the right will be closestRight = x * (floor + 1).
- Finally, the closest number among them will be min(num – closestLeft, closestRight – num).
Below is the implementation of the above approach:
- Find multiple of x closest to or a ^ b (a raised to power b)
- Multiple of x closest to n
- Find K Closest Points to the Origin
- Find the number closest to n and divisible by m
- Find number from given list for which value of the function is closest to A
- Find the closest and smaller tidy number
- Find the largest multiple of 2, 3 and 5
- Find the largest multiple of 3 | Set 1 (Using Queue)
- Find First element in AP which is multiple of given prime
- Find the largest multiple of 3 from array of digits | Set 2 (In O(n) time and O(1) space)
- Closest perfect square and its distance
- Closest sum partition (into two subsets) of numbers from 1 to n
- Minimum absolute difference of a number and its closest prime
- Multiple Inheritance in C++
- Efficiently check whether n is a multiple of 4 or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.