I'd like to evaluate $$\prod_p\left(1-\frac1p\right)$$ over the $k$ largest previous primes $p\le n/2$, where $n$ is the parameter. E.g., if $n=20$ and $k=3$, I'd like the product to be over the 3 previous primes less than or equal to $20/2=10$: namely, $7,5,3$. The code for the previous prime is PreviousPrime[n_Integer] := Block[{i = n}, While[! PrimeQ[-i]]; i] SetAttributes[PreviousPrime, Listable]; How can I take a product over $k$ previous primes?