Solves CodeEval challenge "Ugly Numbers" https://www.codeeval.com/public_sc/42/