[Community Puzzle] Zhiwei Sun Squares

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @David_Augusto_Villa,validated by @About,@jleconte and @Nagato_Uzumaki.
If you have any issues, feel free to ping them.

This is nuts, but if you google Sun Zhiwei the wikipedia is helpful and points to a paper published by the same guy that shows exactly what the problem would like you to accomplish, see here. Basically, solve for all the possible solutions of the second equation first b+3c+5d=e^2 and then use the solutions of that to find the solutions to the larger problem which is an example of Lagrange’s four-square theorem. Hopefully this’ll help somebody that’s never heard of any of this stuff before like me.

Yes, this is rooted in real math. It’s great that you’ve researched it and shared what you found. The problem will time out with a naive approach, and starting with the second equation would greatly reduce the amount of computation. It’s probably the best way, but for those who just tackle it on their own, there are other ideas that will work just fine for this setup, even starting with the first equation. Cheers!

I solved it with simple brute-force dealing with the square-sum equation first.

Handling the second equation first should be faster but algebra is not my cup of coffee. BF with timely breaks is good enough.

Yeah, BruteForce is the way here. Maths are now too far gone from my mind, for me :frowning:

Added tags for Algebra and Nested Loops.