# Serret's algorithm and Fermat's theorem on sums of two squares

Serret's algorithm(1848) proved Fermat's theorem on sums of two squares as follows: $p\equiv1\pmod4, u^2+1=kp, 1\leqslant u<\frac{p}2$

$r_0=p, r_1=u$, then Euclidean Algorithm $$r_0=q_1r_1+r_2$$ $$r_1=q_2r_2+r_3$$ $$...$$ $$r_{k-2}=q_{k-1}r_{k-1}+r_k,$$ where $r_{k-1}>\sqrt{p}>r_k$. then determine $t_k$ such that $r_k\equiv ut_k\pmod p$ with $1\leqslant |t_k|<\sqrt{p}$ ?
we get that $r_k^2+t_k^2=p$

How to prove $1\leqslant |t_{k}|<\sqrt{p}$? thanks!

-
See this page for a hint: numbertheory.org/php/euclid.html –  Yuval Filmus Aug 18 '12 at 12:35