Adding pieces on NxN chess board sequentially The problem is:
Given a $N\times N$ chess board, if you put $B$ pieces starting on square $1,1$ and going right, then down, then left, then up when possible (thus, forming an spiral), in which coordinate the last piece would be put?
Example: $8\times8$ board, $53$ pieces
Putting $8$ on first row, then $7$ down, then $7$ left, then $6$ up, then $6$ right and so on, would give me position (row $4$, col $6$)
Please note the iterative solution is too costly, as $N$ can go up to $2^{30}$ and $B$ up to $2^{60}$.
 A: Assuming we have completed $x$ spirals (and no more spirals can be completed) 
Then we have
(Comparing number of pieces utilized by $x$ and $x+1$ spirals)
$$ n^2-(n-2x)^2\le B\le n^2-(n-2x-2)^2$$
Now,$$n^2-(n-2x)^2\le B\implies n^2-B\le (n-2x)^2\implies x\le\frac{n-\sqrt{n^2-B}}{2}$$
Or,
$$n^2-(n-2x-2)^2\ge B\implies n^2-B\ge (n-2x-2)^2\implies x\ge\frac{n-\sqrt{n^2-B}}{2}-1$$
We get
$$\frac{n-\sqrt{n^2-B}}{2}-1\le x\le\frac{n-\sqrt{n^2-B}}{2}$$
For our purpose we can safely say 

$$\left\lceil{\frac{n-\sqrt{n^2-B}} {2}}-1\right\rceil=x=\left\lfloor{\frac{n-\sqrt{n^2-B}} {2}}\right\rfloor$$

Now we have number of completed spirals then it's not difficult to obtain position of last piece.
A: Here’s a slightly different approach, slightly less elegant but possible just a little more intuitive.
The first full spiral uses $4(N-1)$ pieces. The second spiral is essentially the first on an $(N-2)\times(N-2)$ board, so it uses $4(N-3)$ pieces. Thus, $s$ full spirals use
$$4\sum_{k=1}^s(N-2k+1)=4s(N+1)-8\sum_{k=1}^sk=4s(N+1)-4s(s+1)=4s(N-s)$$
pieces. 
Consider the function $f(x)=4x^2-4Nx+B$; for a non-negative integer $s$, $f(s)$ is the number of pieces remaining after $s$ full spirals have been covered. As a first step we want to find $s$ such that $f(s)\ge 0$, but $f(s+1)<0$. The graph of $y=f(x)$ is a parabola opening up, so if $x_0$ is the smaller $x$-intercept, we want $s\le x_0<s+1$, i.e., $s=\lfloor x_0\rfloor$. Clearly
$$x_0=\frac{4N-\sqrt{16N^2-16B}}8=\frac12\left(N-\sqrt{N^2-B}\right)\;,$$
so
$$s=\left\lfloor\frac{N-\sqrt{N^2-B}}2\right\rfloor\;.$$
The $s$-th full spiral ends at square $\langle s+1,s\rangle$ (where I’m giving the row number first). If $f(s)=0$, that’s where we end up. Otherwise, the remaining $f(s)$ pieces partially cover the $(s+1)$-st spiral, whose upper lefthand corner is square $\langle s+1,s+1\rangle$ and whose sides contain $N-2s$ squares. Thus, we end at
$$\begin{cases}
\langle s+1,s+f(s)\rangle,&\text{if }f(s)\le N-2s\\
\langle 3s+1+f(s)-N,N-s\rangle,&\text{if }N-2s\le f(s)\le 2N-4s-1\\
\langle N-s,3N-5s-1-f(s)\rangle,&\text{if }2N-4s-1\le f(s)\le 3N-6s-2\\
\langle 4N-7s-2-f(s),s+1\rangle,&\text{if }3N-6s-2\le f(s)<4N-8s-2\;.
\end{cases}$$
For example, if $N=8$ and $B=46$, then
$$s=\left\lfloor\frac{8-\sqrt{64-46}}2\right\rfloor=\left\lfloor 4-\frac{\sqrt{18}}2\right\rfloor=1\;,$$
$f(s)=4-32+46=18$, and since $24-6-2=16\le 18$ we end at 
$$\langle 32-7-2-18,2\rangle=\langle 5,2\rangle\;.$$
