M = 2005 = 5*401, M = 25, M = 401*401 all work.Originally Posted bymathsmad

If M is allowed to be prime, any prime number not equal to 5 or 401 will do.

If M is composite and has a prime factor other than 5 or 401, there will be too many factors. Similar if M is divisible by 5*5*401 or 5*401*401.

So only powers of 5 or 401 remain. Counting divisors for the cases M = 5^k, k > 2 and M = 401^k, k > 2 shows that these have too many divisors. This implies that the cases given above are the solution set.