Thanks in advance for the help.
Suppose I have two integers, $a$ and $b$. I want to find the multiple of $a$ that is less than $b$ but closest to $b$. For example, suppose $a = 3$ and $b = 15$. The answer here would be 12.
Asked another way, I want to find the largest multiple of $a$ that is less than $b$.
Is there a constant time algorithm to do this? If not, is using modular arithmetic the most efficient solution?
edit:
I know how to solve this problem. I'm asking if there is a way to solve this problem in constant time (ie computational complexity). Modular, multiplication (ie division), and addition are not constant time operations. See https://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations from more info regarding computational complexity.
I should have been more clear too. I don't believe that there is a constant time algorithm, but I could be wrong. Even if there isn't what would be the most computationally efficient way of solving this?