Sounds exactly like my experience doing Project Euler. I learned a lot about mathematics from it. I don't know how much of it actually helped me as a programmer, because I don't tend to run into problems of this nature (not that I notice, anyway), but it was fun.