# Julia, 59 bytes <!-- language-all: lang-julia --> !n=sort(map(prod,combinations(17n|>primes,7))-n,by=abs)[]+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 **64 bytes** – efficiency can be improved dramatically. !n=sort(map(prod,combinations(n>>14+17|>primes,7))-n,by=abs)[]+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**. ### How it works `17n|>primes` and `n>>14+17|>primes` (the bitshift is equivalent to dividing by **2<sup>14</sup> = 16384**) compute the prime ranges mentioned in the previous paragraph. Then, `combinations(...,7)` computes all arrays of seven different prime numbers in that range, and mapping `prod` over those calculates their products, i.e., the 7DP numbers from which we'll choose the answer. Next, `-n` subtracts **n** prom each 7DP number, then `sort(...,by=abs)` sorts those differences by their absolute values. Finally, we select the first difference with `[]` and compute the corresponding 7DP number by adding **n** with `+n`. [Try it online!]: http://julia.tryitonline.net/#code=IW49c29ydChtYXAocHJvZCxjb21iaW5hdGlvbnMoMTdufD5wcmltZXMsNykpLW4sYnk9YWJzKVtdK24KCnByaW50bG4oITUpCgohbj1zb3J0KG1hcChwcm9kLGNvbWJpbmF0aW9ucyhuPj4xNCsxN3w-cHJpbWVzLDcpKS1uLGJ5PWFicylbXStuCgpwcmludGxuKCE4NjA3ODIpCnByaW50bG4oITE0MjUwNjAp&input= [@LuisMendo's answer]: http://codegolf.stackexchange.com/a/82355 [On the interval containing at least one prime number]: http://projecteuclid.org/euclid.pja/1195570997