That's unfair. The episode aired six years before the proof.
For a show that loves to bask in how awesome and perfect humanity has become (and even saying we might become god like one day), I find it silly how the writers believed that humanity still wouldn't be able to figure out Fermat's theorem in 300 years. Sure, at the time this episode aired it wasn't solved, but now that there's proof, the use of it excusing poor writing just adds to the laziness of the writing.
Star Trek is a show that examines a lot of 'what if's'. What if the galaxy was full of intelligent life? What if we invented the technology to travel the galaxy and meet/make alliances with those alien races? What if we got past many of the problems we face today, such as war, famine, etc?
Star Trek does paint a positive view of the future (thankfully), but does it try to say that we got past every
problem? Absolutely not. Of course, DS9 went a little deeper into some of these problems and shades of grey with Section 31, the Maquis, etc, but it certainly existed in TNG as well. We're not portrayed as perfect beings who solve every problem instantly and never make mistakes. Heck, even Wesley the wonder boy made serious mistakes
Who's to say that every unsolved question/problem we have today will be answered by the 24th century? To say that the writers should have known exactly which problems we will be able to solve in the future (whether technologically, socially, morally or even mathematically), is unrealistic. Science Fiction movies/shows set in the future get things wrong. It just happens.
There are much bigger problems to complain about than the use of the 'unsolved' theorem in this episode.