biginteger – Overflow integer but correct answer in C++

You will always get 1 if they are Pythagorean triples, but not necessarily always 0 when they are not.

This is because if x == y then x % n == y % n; but if x != y it is not necessarily true that x % n != y % n. For example, if 10 == 10 then 10 % 3 == 10 % 3; but even though 10 != 16, it is not true that 10 % 3 != 16 % 3.

EDIT: I didn’t even notice a wrong operator was used in code. Using C’s ^ you cannot generate overflow, and aren’t actually testing Pythagorean triples; if you change to a*a + b*b == c*c instead, the above should hold.

Read more here: Source link