# Question related to matrix in computer memory

I'm trying to solve the following problem from a book:

A matrix $\mathbb M$ has 3 rows and 4 columns:

$$\left[ \begin{array}{cccc} a_{11} & a_{12} & a_{13} & a_{14}\\ a_{21} & a_{22} & a_{23} & a_{24}\\ a_{31} & a_{32} & a_{33} & a_{34}\\ \end{array} \right]$$

The 12 entries in the matrix are to be stored in row major form in locations 7,609 to 7,620 in a computer’s memory. This means that the entries in the ﬁrst row (reading left to right) are stored ﬁrst, then the entries in the second row, and ﬁnally the entries in the third row. Find formulas (in $n$) for $r$ and $s$ so that $a_{rs}$ is stored in location 7,609 + $n$.

So far I have come up with this relation among $r$, $s$ and $n$ (which is fairly common in matrix calculations):

$$4 \cdot (r-1) + s - 1 = n$$

But I can't seem to find the second relation that will allow me to express $r$ and $s$ in terms of $n$. Any help is greatly appreciated.

-

For the rows, we want to come up with a function that will map $\{0,1,2,3\}$ to $1$, $\{4,5,6,7\}$ to $2$, and $\{8,9,10,11\}$ to $3$. This suggests that we use a floor function as follows: $$r=1+\lfloor n/4 \rfloor$$
For the columns, we want to come up with a function that will map $\{0,4,8\}$ to $1$, $\{1,5,9\}$ to $2$, $\{2,6,10\}$ to $3$, and $\{3,7,11\}$ to $4$. This suggests that we take the remainder as follows: $$s=1+(n \bmod 4)$$
Wow! Thanks so much! I did try all this while to find out a relation. I was trying variations of $\lfloor n/4 \rfloor + 1 - (-1)^n$, which was of course not working. In retrospect, it should have been easy to anticipate the functions, given that this chapter had introduced div and mod. :) – dotslash Jul 18 '13 at 5:05
Also formally (using $0\le s-1<4$) we have $\lfloor\frac{4(r-1)+(s-1)}{4}\rfloor =r-1$ and $4(r-1)+(s-1)\equiv s-1\pmod 4$ – Hagen von Eitzen Jul 18 '13 at 5:50