Transforming 3D matrix into 1D matrix and back I have a 3D matrix of size $n \times n \times n$.
I know that, in order to convert it to a 1D matrix, I can simply assign to element $i,j,k$ the number
$$N(i,j,k)=(i\ \% \ n)+(j \ \% \ n)\cdot n + (k \ \% \ n) \cdot n^2$$
where $\%$ denotes the reminder of the division (modulo operator).
For example, for $n=3$ we will have
$$N(0,0,0) = 0\\N(1,0,0)=1\\N(2,0,0)=2\\N(0,1,0)=3\\N(1,1,0)=4\\N(2,1,0)=5\\\dots$$
My question is: what is the inverse function that allows me to go from $N(i,j,k)$ to $i,j,k$ (from 1D to 3D matrix)?

Edit
I adapted  the formula from a more general case and didn't notice that in my case the modulo is indeed unnecessary...
As suggested in the comments and answers, it is sufficient to define
$$N(i,j,k)=i+j\cdot n + k \cdot n^2$$
 A: It's not technically a matrix... this is array indexing, a common way of encoding multidimensional data (such as photos, simulation grids etc) in computer memory.
The process is exactly the same as expressing a number in a certain basis. You can even have different dimensions (let's say I,J,K). Mapping from 3D to 1D:
$$(i,j,k)\mapsto i + j\cdot I +k \cdot I\cdot J=i+I\cdot (j+J\cdot (k))=N$$
The second form tells you how to invert the transformation. Everything except $i$ is divisible by $I$, so you get
$$i=N\mod I; \quad (j+J\cdot (k) ) = \lfloor N/I \rfloor$$
You see this is recursive. You split $N$ into $i$ and what was multiplied by $I$. You proceed for arbitrary number of dimensions:
$$j= \lfloor N/I \rfloor \mod J;\quad k= \lfloor\lfloor N/I \rfloor/J\rfloor=\lfloor N/(IJ)\rfloor$$
Compare with this:
$$3 + 5\cdot 10 + 7\cdot 10\cdot 10=753$$
$$3=753\mod 10;\quad 75 = \lfloor 753/10 \rfloor$$
$$5=75\mod 10;\quad 7 = \lfloor 75/10\rfloor$$
To sum up: no matter what "shape" of multidimensional rectangular array you have, you do basis conversion in both directions.

Of course, there are two main standard conventions from which side you start folding the number (row major / column major for arrays in different programming languages, little-endian / big-endian for bit order, and left-to-right and right-to-left for number systems, where arabic is written with most significant digit first), and a bunch of less common ones, but this goes beyond mathematical question into the realm of data structures and encoding.
A: We usually call a "3D matrix" a third-order tensor.
By construction $N(i, j, k)$ is just $kji_n$---that is, the base-$n$ number with $n^2, n, 1$ place values $k, j, i$, respectively.
Thus, we can extract the arguments $i, j, k$ as usual, via
\begin{align}
i &= N(i, j, k) \mod n \\
j &= \left\lfloor \frac{N(i, j, k)}{n} \right\rfloor \mod n \\
k &= \left\lfloor \frac{N(i, j, k)}{n^2} \right\rfloor \mod n .
\end{align}
Here $\mod{}$ is the modulo operator.
The generalization to $m$th-order tensors follows the same pattern.
A: The most efficient way (because this only takes two divisions):
i= N
j= i / n
i-= j . n
k= j / n
j-= k . n

