I have a vector $\mathbf{x} = [x\_{11}, x\_{12}, \ldots, x\_{1n}, x\_{21}, x\_{22}, \ldots, x\_{2n}, \cdots, x\_{m1}, x\_{m2}, \ldots, x\_{mn}]^T$ of size $m\cdot n$.

My problem is this:

> 
> Given an index $p$ from $1$ to $m\cdot n$, find the indexes $i$ and $j$ of the corresponding element $\mathbf{x}[p]$, i.e., $x\_{ij}$.
> 
> 
> Example: For $m=n=3$, $\mathbf{x} = [x\_{11}, x\_{12}, x\_{13}, x\_{21}, x\_{22}, x\_{23}, x\_{31}, x\_{32}, x\_{33}]^T$ and $p=5$. Find $\mathbf{x}[p]$?
> The answer is: $\mathbf{x}[p]=x\_{22}$. Hence, $i=j=2$.
> 
> 
> 

My solution is the following:

Given $p$,

$$ i = \left\lceil\dfrac{p}{m}\right\rceil,$$
$$ j = p - (i - 1) \* n .$$

But I think it is wrong.