Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let n and p be any positive integer, make $p$ the subject of the equation: $(3n + p)\bmod4 = 0$. How is it done?

I've worked out that the only values for p are 1, 2, 3 and 0.

This formula is for calculating the amount of padding required in a bitmap's pixel array:

Padding bytes (not necessarily 0) must be appended to the end of the rows in order to bring up the length of the rows to a multiple of four bytes. When the Pixel Array is loaded into memory, each row must begin at a memory address that is a multiple of 4. This address/offset restriction is mandatory only for Pixel Array's loaded in memory. For file storage purposes, only the size of each row must be a multiple of 4 bytes while the file offset can be arbitrary.[1] A 24-bit bitmap with Width=1, would have 3 bytes of data per row (blue, green, red) and 1 byte of padding, while Width=2 would have 2 bytes of padding, Width=3 would have 3 bytes of padding, and Width=4 would not have any padding at all.

share|cite|improve this question
I don't understand the terminology: what does it mean to make a term that appears in an equation "the subject of the equation"? Do you mean you want to solve the congruence for $p$? If so, the answer is $p \equiv n \pmod 4$. – Pete L. Clark Apr 14 '11 at 16:37
Yes, you are absolutely correct, solve for congruence p. – meiryo Apr 14 '11 at 17:03
up vote 2 down vote accepted

It depends on the value of $n$.

If $n \equiv 1$ (mod 4), then, you have $3+p\equiv0$ (mod 4) which means that $p\equiv1$ (mod 4). This procedure can be repeated for other values of $n$, namely $n\equiv0,1,2,3$ (mod 4)

In addition to this, note that if $p\equiv n$ (mod 4), then you have that $3n+p=4n\equiv0$ (mod 4)

share|cite|improve this answer
Thanks picakhu. – meiryo Apr 14 '11 at 17:02

$\rm\: mod\ 4\::\ \ 3\equiv -1\ $ so $\rm\ 0\ \equiv\ p + 3\:n\ \equiv\ p - n\ \iff\ p\ \equiv\ n\ \ $ by basic modular arithmetic.

Alternatively $\rm\ 4\ |\ p + 3\:n\ \iff\ 4\ |\ p - n + 4\:n\ \iff\ 4\ |\ p - n\ \ $ where $\rm\ a\ |\ b\ $ means $\rm\:a\:$ divides $\rm\:b\:.$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.