That's an elegant way to do it. For a brief moment I considered solving this by hand using basically the same idea, but that gets incredibly painful before I even got started.
I mean, obviously the extremes get eliminated right away, and then the primes, but then I have to track 10,000 number combinations.