Determine position of number in a grid of numbers centered around 0 and increasing in spiral
===

I've got the following grid of numbers centered around 0 and increasing in spiral. I need an algorithm which would receive number and return x; y - numbers of moves how to get to that number from 0. For example for number 9 it would return -2; -1. For 4 it would be 1; 1.


    25|26|... etc.
    24| 9|10|11|12
    23| 8| 1| 2|13
    22| 7| 0| 3|14
    21| 6| 5| 4|15
    20|19|18|17|16

This spiral can be slightly changed if it would help the algorithm to be better.
Use whatever language you like. I would really appreciate mathematical explanation.

Thank you.