Given some $b \in \mathbb Z^+$, efficiently find all values for $a \in \mathbb Z^+$ such that...
- $1 \le a \le b$.
- $a^2 + b^2$ is a perfect square.
Efficiently means with a method faster than testing all the values in $[1, b]$.
Given some $b \in \mathbb Z^+$, efficiently find all values for $a \in \mathbb Z^+$ such that...
Efficiently means with a method faster than testing all the values in $[1, b]$.
Copyright © 2021 JogjaFile Inc.
It is necessary to expand the number in $b^2$ into two different factors $b^2=p_1\cdot p_2$ where $p_1<p_2$ and both of them even or both of them odd. Then solve the system of equations:$$c-a=p_1; c+a=p_2$$ $$c=\frac{p_1+p_2}{2}; a=\frac{p_2-p_1}{2}$$