一開始以為要暴力解再優化,沒想到是數學題.
X^2 + Y^2 = Z^2,
where X, Y and Z are relative-prime integers, then
X = R^2 - S^2
Y = 2RS
Z = R^2 + S^2
where R, S are also relative-prime integers, and ONLY one of them is EVEN.
然後我也發現 loop 1,000,000次是非常快的事,這個數值可以記一下。
沒有留言:
張貼留言