How many numbers between two numbers say $low$ and $high$ can be expressed in the form of
A*x+B*y
where the values of A and B are known to us and low and high is also given to us ? Here all quantities are integers .
How many numbers between two numbers say $low$ and $high$ can be expressed in the form of
A*x+B*y
where the values of A and B are known to us and low and high is also given to us ? Here all quantities are integers .
Copyright © 2021 JogjaFile Inc.
As you already noticed, you can only represent multiples of the gcb of $A, B$. Specifically, let $L \le H$ be the bounds and $d = (A, B)$, then you're looking for $\left|d\Bbb Z \cap [L, H]\right|$.
You may reduce the problem by making $d = 1$, but I don't think it's really necessary. Just note that $\min d\Bbb Z \cap [L, H] = \lceil \frac Ld \rceil d$, and similarly $\max d\Bbb Z \cap [L, H] = \lfloor \frac Hd \rfloor d$, so
$$\left|d\Bbb Z \cap [L, H]\right| = \frac {\lfloor \frac Hd \rfloor d - \lceil \frac Ld \rceil d}{d} + 1 = \lfloor \frac Hd \rfloor - \lceil \frac Ld \rceil + 1$$