Approximating a number by using only a given set of prime-factors for the approximant.

61 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.