--- from: http://rosettacode.org/wiki/Tonelli-Shanks_algorithm