+ 3
How to improve the code?
The object of the program is to identify all the Pythagorean triples for : a + b + c = N such that a^2 + b^2 = c^2 where a < b < c I tried to use the logic: a + b + c = N such that a^2 + b^2 = c^2 where a < b < c and a = 2mn, b = m^2 - n^2, c = m^2 + n^2 where m > n but it would not produce all 8 triplets for N = 840 which I had got from a Euler proof. What else could be used to speed this up? https://code.sololearn.com/cpuk3QOT0Gdb/?ref=app
4 ответов
+ 2
William Owens in about half of the iterations c is negative so it is doing unnecessary calculations.
+ 1
If I run your code for input 840, it does show 8 results (correctly).
Did you manage to fix it? or I don't see the bug.
+ 1
I was testing with N=840, but you can cause c to go negative with only N=2.
0
Brian What are you using for N to get the negatives?