In a modular arithmetic equation, how to find 'a' given a range?

Say I have an equation in the form

$$a\bmod b = c$$

I know $b$ and $c$ I'm given a range $(d,e)$ (where $d$ and $e$ are integers). How can I find all values of $a$ that satisfy the inequality $d \le a \le e$?

• Well, "a = c (mod b)" means $a = c + bn$ for some integer n. Now you just need to solve for n given your range.
– lulu
Commented Jul 27, 2015 at 0:11
• @lulu Right, my problem is finding an algorithm of some sort that will calculate that between a range
Commented Jul 27, 2015 at 0:17
• Well, first solve for $c+bn = d$ (probably not an integer). the least n that works is the least integer greater than or equal to that value. Similarly solving $c+bn= e$ gives you an upper bound. All the integers in between will work.
– lulu
Commented Jul 27, 2015 at 0:24

Find all multiples of $b$ that are between $d-c$ and $e-c$, and add $c$ to each of them.
The reason is that such an $a$ can be written $c+kb,\enspace k\in\mathbf Z$. Write the range inequalities: $$d\le c+kb\le e\iff d-c\le kb\le e-c.$$ Once you have all $kb$ that satisfie these conditions, by definition, $a= kb+c$.