Tonelli - Shanks algorithn