For a given number $n$, I am interested in the closest number that can be written as a product of a given set of prime factors. More precisely, I am interested in a solution of the following problem for a given natural number $n$ and a given set of prime numbers $p_1, \ldots, p_j$:
$$ \min_{a_1, \ldots, a_j \in \mathbb N} \left| n - \prod_{i=1,...,j} p_i^{a_i} \right| $$
The background of this question comes from signal processing. Given a signal of length $n$ it is often possible to pad or crop the signal to a length close to $n$ without affecting the overall processing much. However, by padding/cropping one can get a signal length which allows for fast FFT computation as it has many divisors.
Taking the logarithms, you are trying to maximize
$$\sum a_i\log p_i$$ under constraints $$a_i\ge0,\\\sum a_i\log p_i\le\log n$$ or minimize it under constraints $$a_i\ge0,\\\sum a_i\log p_i\ge\log n$$ and keep the best solution.
This is a linear integer programming problem. Chances are high that it is NP-hard and you can't do much better than brute-forcing.