0
$\begingroup$

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$?

$\endgroup$
3
  • 3
    $\begingroup$ Well, "a = c (mod b)" means $a = c + bn$ for some integer n. Now you just need to solve for n given your range. $\endgroup$
    – lulu
    Commented Jul 27, 2015 at 0:11
  • $\begingroup$ @lulu Right, my problem is finding an algorithm of some sort that will calculate that between a range $\endgroup$
    – chad
    Commented Jul 27, 2015 at 0:17
  • $\begingroup$ 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. $\endgroup$
    – lulu
    Commented Jul 27, 2015 at 0:24

1 Answer 1

1
$\begingroup$

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$.

$\endgroup$
4
  • $\begingroup$ Could you give a brief explanation as to why this works? $\endgroup$
    – chad
    Commented Jul 27, 2015 at 0:15
  • $\begingroup$ Here are the details. Is it clear? $\endgroup$
    – Bernard
    Commented Jul 27, 2015 at 0:28
  • $\begingroup$ I do apologize, I'm kind of new at this. What does the '⟺' symbol mean? $\endgroup$
    – chad
    Commented Jul 27, 2015 at 0:32
  • $\begingroup$ You're welcome. It means ‘if and only if’, or ‘ is logically equivalent’. I just followed the usual rules for inequalities. $\endgroup$
    – Bernard
    Commented Jul 27, 2015 at 0:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .