Elegance beats exhaustion. Brute force is not the way!
Complete solutions in C++, Python & Java — with step-by-step mathematical explanations