Skip to main content
2 of 5
added 1162 characters in body
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Julia, 52 bytes

!n=minabs(map(prod,combinations(17n|>primes,7))-n)+n

This is very inefficient, but it works for the first test case in practice and for the others in theory.

At the cost of 5 more bytes – for a total of 57 bytes – efficiency can be improved dramatically.

!n=minabs(map(prod,combinations(n>>14+17|>primes,7))-n)+n

Try it online!

Background

As mentioned in @LuisMendo's answer, the set of primes we have to consider for the nearest 7DP number is quite small. It suffices for the set to contains a 7DP number that is bigger than the input n, which will be true if and only if it contains a prime p ≥ 17 such that 30300p = 2·3·5·7·11·13·p ≥ n.

In On the interval containing at least one prime number proves that the interval [x, 1.5x) contains at least one prime number whenever x ≥ 8. Since 30030 / 16384 ≈ 1.83, that means there must be a prime p in (n/30030, n/16384) whenever n > 8 · 30300 = 242400.

Finally, when n < 510510, p = 17 is clearly sufficient, so we only need to consider primes up to n/16384 + 17.

At the cost of efficiency, we can consider primes up to 17n instead. This works when n = 1 and is vastly bigger than n/16384 + 17 for larger values of n.

Dennis
  • 210.6k
  • 41
  • 370
  • 825