Hehehe, yea, there's almost always a slicker way than brute force in math... Especially in number theory. Brute force rarely works. My teach always made it so that brute force wouldn't work/would take forever however, if we managed to see it from a certain angle, it becames fairly easy 🙂
I really think you're going about it the wrong way!