Let $n \in\mathbb{N},$ and $S$ be a (finite) set of prime numbers.
I'm looking for an efficient algorithm to find the greatest $m\leq n$ such that $m$'s prime factors are of $S$?
For $S=\{p\}$ the answer is $\;m = p^{\lfloor\log_{p}(n)\rfloor}\;$ where $\lfloor x \rfloor$ denotes the floor of $x$.
For $S=\{p, q\}$ the aim would be to aproximate $\ln(n)$ as: $$\;a\ln(p) + b\ln(q)$$ where $a$ and $b$ are natural numbers (ie. $p^aq^b = n$). However, I'm not sure where to go from here.
If S is not too large, say 10 elements, then you can systematically enumerate all integers made of factors in S.
If S is so large that a substantial fraction of integers are made of factors in S, then you should be able to create a sieve containing all numbers with factors not in S.