That is not necessarily a math puzzle. Sounds more like a programming task formalization using math notation if you take the brute force search approach. Using math concepts helps too phrase interview questions in a non-ambiguous way, like "write a function printing all prime numbers in the range 2 <= n <= 1000".