Doing a coding assignment. And it's basically having a user enter $n$. Then I need to provide (If it exists) $$n = x^2 + y^2 + z^2.$$
Not really sure how to approach this. Any ideas?
Doing a coding assignment. And it's basically having a user enter $n$. Then I need to provide (If it exists) $$n = x^2 + y^2 + z^2.$$
Not really sure how to approach this. Any ideas?
Copyright © 2021 JogjaFile Inc.
So following from Lab's link we have $$n=x^2+y^2+z^2\iff n\ne4^a(8b+7)$$ Therefore to test we divide by 4 as much as possible at least once. Then subtract 7 and test if it is divisible by 8. If the divisibilities are true then you have a number that can't be represented as such.
Algorithm