Project Euler flashbacks. When your solution has an astronimcal search space derive the neat math trick to solve it instead.