Not cheating, but you are correct -- there's a possible ethical(?) problem. But not in this case.
If you were given, say, a placement exam and specifically told it's about problems you've never seen, clearly you should speak up about ones you've coincidentally studied. Ethically, you're lying by implicitly presenting it as "here's how I solved a problem which I have never, ever seen before". And of course, it's in your best interest to be placed correctly. One could construct examples where it's less and less important and less and less dishonest. A problem on a school test is somewhere below 0 on that scale.
You're probably getting an A either way, and one test isn't that big a thing, and minor changes in grades don't matter than much anyway, and if you did so well your score will be left out of the curve (if there is one). You were only told about "to see how you handle a problem you've never seen" afterwards, and there's no practical way to fix it (the instructor is not going to find a new problem for you), and it's already understood that tests contain a certain element of luck as far as what-they-studied vs. what's-on-the-test.
I've had students come in and tell me they got 2 extra points on an exam (their final score was 2 points higher than if you added the points they got for each problem). That's fun. I generally dead-pan it, telling them it would be too much trouble to change but I'll try to keep it in mind for final grades. If you wanted to bring this up with the instructor, they'd probably be amused, understand where the impulse came from, and not consider for even a fraction of a second that this was anything they needed to fix.