Have a book open that is related to what you're doing and is interesting to you that you can use to take a quick break every now and then. For example, you're solving a complex set of problems, I take it you're interested in math? If I were in your shoes I'd have something like this open in another tab to distract myself, or more realistically easier problems from Khan Academy since I'm terrible at math. Ha. The point is, distract yourself productively until you're willing to come back to the problem at hand.