This may not be the most optimal solution...
Essentially we are looking for all possible {(x, y, z) | (2^x * 3^y * 5^z) <= K}
- When x+y+z = 1, we get {2, 3, 5},
- Let:
S(i) = { (2^x * 3^y * 5^z) | (2^x * 3^y * 5^z) < K and (x + y + z = i)}
S(i, j) = Union of all s in S(i-1, t) * j that:
a. t and j belong to {2, 3, 5}
b. t >= j
c. s <= K
for example:
S(2,2) = {2, 3, 5} * 2 = {4, 6, 10}
S(2,3) = {3, 5} * 3 = {9, 15}
S(2,5) = {5} * 5 = {15} - S(i) = S(i-1, 2) + S(i -1, 3) + S(i-1, 5).
for example:
S(2) = S(2,2) + S(2,3) + S(2, 5) - Stops when S(i) is empty.
No comments:
Post a Comment