Expanding integers into distinct egyptian fractions - what is the optimal way?

There are many algorithms for decomposing some $\frac{p}{q}\in\mathbb{Q}^+$ as $$ \frac{p}{q}=\sum_{a\in A\subset\mathbb{Z}^+}\frac{1}{a}$$ for instance the greedy algorithm, but the answer to your question strongly depends on what you mean by optimal. If you mean with the least number of terms, the question is not trivial at all: in fact, it is an open problem. Anyway it is not difficult to prove by induction that the greedy algorithm or the algorithm based on the identity $\frac{1}{n}=\frac{1}{n+1}+\frac{1}{n(n+1)}$ stops at some point for any $\frac{p}{q}\in\mathbb{Q}^+$.

Here it is a representation of $2$ I found by combining the two approaches: $$ 2 = \frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6}+\frac{1}{7}+\frac{1}{8}+\frac{1}{10}+\frac{1}{12}+\frac{1}{15}+\frac{1}{40}+\frac{1}{140}$$ It has $12$ terms, $A=\{2,3,4,5,6,7,8,10,12,15,40,140\}$ and $\prod_{a\in A}a\approx 4\cdot 10^{11}.$

Another representation with twelve terms is given by $A=\{2,3,4,5,6,7,8,9,10,15,230,57960\}$ with $\prod_{a\in A}a\approx 7.2\cdot10^{14}$.

Yet another one is given by $A=\{2,3,4,5,6,7,8,9,12,14,63,2520\}$ with $\prod_{a\in A}a\approx 10^{13}$.

After a long search, I also found a representation for $3$ with just $33$ terms, given by $A=[2,18]\cup[20,28]\cup\{30,32,33,34,864,199836,7813587600\}$.