[Question]
  [
An Egyptian fraction is a representation of a rational number using the sum of distinct unit fractions (a unit fraction is of the form \$ \frac 1 x \$ where \$ x \$ is a positive integer).
For all**[1]** positive integers \$ n \ne 2 \$, there exists at least one Egyptian fraction of \$ n \$ distinct positive integers whose sum is \$ 1 \$. For example, for \$ n = 4 \$:
$$ \frac 1 2 + \frac 1 4 + \frac 1 6 + \frac 1 {12} = 1 $$
Here is another possible output:
$$ \frac 1 2 + \frac 1 3 + \frac 1 {10} + \frac 1 {15} = 1 $$
The number of possible outputs is given by [A006585](https://oeis.org/A006585) in the OEIS.
**[1]**: I cannot find a direct proof of this, but I can find [a proven lower bound](https://mathweb.ucsd.edu/%7Eronspubs/80_11_number_theory.pdf) on A006585, which has this as an obvious consequence. If you can find (or write!) a better / more direct proof that a representation exists for all \$ n \ne 2 \$ I would love to hear it.
## Task
Given \$ n \$, output a list of positive integers representing the denominators of *at least one* valid solution of length \$ n \$.
You may alternatively output a list of rational numbers which are unit fractions, but only if they are an exact representation of the value (so not floating-point).
## Test cases
I only list a few possible outputs. [Here is a Ruby program which can verify any solution](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN00LSkuKNdJTS4r1igtyMks0lHQUlDT1chMLqmsyaxQMixT0FTL1SvLji2r1iktzFWxtgWKaEM1QMxbcVDOy0FEwMtFRMATShqZADGIbAbGBjoKljgJQ1FxHwQyiHAA).
```
n     outputs
1     {1}
3     {2, 3, 6}
4     {2, 4, 6, 12} or {2, 3, 10, 15} or {2, 3, 9, 18} or {2, 4, 5, 20} or {2, 3, 8, 24} or {2, 3, 7, 42} or ...
5     {2, 4, 10, 12, 15} or {2, 4, 9, 12, 18} or {3, 4, 5, 6, 20} or {2, 5, 6, 12, 20} or {2, 4, 8, 12, 24} or {2, 4, 7, 14, 28} or ...
8     {4, 5, 6, 9, 10, 15, 18, 20} or {3, 5, 9, 10, 12, 15, 18, 20} or {3, 6, 8, 9, 10, 15, 18, 24} or {4, 5, 6, 8, 10, 15, 20, 24} or {3, 5, 8, 10, 12, 15, 20, 24} or {4, 5, 6, 8, 9, 18, 20, 24} or ...
15    {6, 8, 9, 11, 14, 15, 18, 20, 21, 22, 24, 28, 30, 33, 35} or {7, 8, 10, 11, 12, 14, 15, 18, 20, 22, 24, 28, 30, 33, 36} or {6, 8, 10, 11, 12, 15, 18, 20, 21, 22, 24, 28, 30, 33, 36} or {6, 8, 10, 11, 12, 14, 18, 20, 21, 22, 24, 28, 33, 35, 36} or {5, 8, 11, 12, 14, 15, 18, 20, 21, 22, 24, 28, 33, 35, 36} or {5, 8, 10, 11, 14, 15, 18, 21, 22, 24, 28, 30, 33, 35, 36} or ...
```
## Rules
* You may output the numbers in any order
* If you choose to output all possible solutions, or a particular subset of them, you must not output duplicates. This includes lists which are the same under some permutation.
* You may assume \$ n \$ is a positive integer, and is not \$ 2 \$
* Your code does not need to practically handle very high \$ n \$, but it must work in theory for all \$ n \$ for which a solution exists
* You may use any [standard I/O method](https://codegolf.meta.stackexchange.com/q/2447)
* [Standard loopholes](https://codegolf.meta.stackexchange.com/q/1061) are forbidden
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
  
[Answer]
# [Python 2](https://docs.python.org/2/), 42 bytes
```
f=lambda n,x=1:1/n*[x]or[x+1]+f(n-1,x*-~x)
```
[Try it online!](https://tio.run/##Fc29DsIgGIXh3as4DgToj/Xr2IQraTpgEMXoR0M64OKtI2wn7/Cc/Xs8I8@lePO2n5uz4CEbWmjibs1bTGvuaeu94pGG3I2/rIuPCYzASJYfd0UD6KqXE4Kv@Www1409BT4ghYOREFWFRA95ecXAStIkXMsODXMNqxdalz8 "Python 2 – Try It Online")
The key thing to observe is that `1/n = 1/(n+1) + 1/(n*(n+1))`. Therefore we can always obtain a solution with `n` fractions, by using a solution with `n-1` fractions, and "splitting" the last fraction in two.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes
```
¡ɾṗ'Ė∑1=;t
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCocm+4bmXJ8SW4oiRMT07dCIsIiIsIjMiXQ==)
Bruteforcer. \$O\left(2^{n!}\right)\$ time complexity, searches for fractions with reciprocals \$ n! \$ which seems to be enough.
```
¡          # Factorial
 ɾṗ        # All combinations of 1...n
   '    ;  # Filtered by...
    Ė∑     # Sum of reciprocals
      1=   # is 1?
         t # Get the last one
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 32 bytes
Using Sylvester's sequence A000058
```
Nest[##&[#^2+#,1+#,##2]&,1,#-1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773y@1uCRaWVktWjnOSFtZxxCIlZWNYtV0DHWUdQ1j1f4HFGXmlTho@WQWA8l0fYdqQx1jHRMdUx2z2v//AQ "Wolfram Language (Mathematica) – Try It Online")
-8 bytes from @att
[Answer]
# [Factor](https://factorcode.org/), 48 bytes
```
[ 1 - 2 [ 3 dupn . sq - abs 1 + ] repeat 1 - . ]
```
[Try it online!](https://tio.run/##HcoxDoJAEEbhnlP8vYEETSjgAIbGxlgRihEG2bgO6@xQyOVXQvu@N9Fgi6bHvb1da3zIZrxYWMm7jcwtEvFmFfYIyma/oE4MTZZVqUOJHGd0uGBcg6BA/O6FnnGXE3ooByY7tgJ9Gsj79Ac "Factor – Try It Online")
Port of @ZaMoC's [Mathematica answer](https://codegolf.stackexchange.com/a/241226/97916). It prints the first n terms of Sylvester's sequence, subtracting 1 from the last number.
The old way that doesn't quite work:
```
[ [1,b] dup 1 rotate v* ]
```
[Answer]
# [R](https://www.r-project.org/), ~~44~~ 38 bytes
*-6 bytes thanks to Dominic van Essen*
```
function(n)2^(1:n)*.75^(n:1<3)-(n<2)/2
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jT9MoTsPQKk9TS8/cNE4jz8rQxlhTVyPPxkhT3@i/RoVtmoaxpiYXV3FproahfoXmfwA "R – Try It Online")
## First Attempt
```
function(n){k<-1:n;2^k*.75^(k>n-2)-(n==1)/2}
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jT7M620bX0CrP2ihOI1tTS8/cFEjb5ekaaepq5NnaGmrqG9X@16iwTdMw0dTk4iouzdUw1K/Q/A8A "R – Try It Online")
Port of my Excel answer.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~70 40~~ 34 bytes
```
->n{a=1;(2..n).map{a*=q=1+a;q}<<a}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOtHW0FrDSE8vT1MvN7GgOlHLttDWUDvRurDWxiax9n@0oY6WsZ6eoUEsWLqmoqZAIS26Irb2PwA "Ruby – Try It Online")
Based on dingledooper's python answer.
Some bytes saved by following Kevin Cruijssen's advice.
[Answer]
# [R](https://www.r-project.org/), ~~55~~ 57 bytes
*Edit: Thanks to Anders Kaseorg (and +2 bytes) for bug-spotting*
```
function(n){while(n<-n-1)T=c((k=T[1]+1)*T[1],k,T[-1]);+T}
```
[Try it online!](https://tio.run/##jY1BCsIwEEX3vYabGdugs1Vzi@xKKSFMbYiOJUkpRTx7tHoBV/8/Po8fi5Wer@uU/acM0brsH9JHniInlmw31GWY5TuA4HMZ/Y1BLkoUodEOIGjTUlcT7rdsQmNaRR2ea/MqYCUtHPUfN0BHxKrauZFdOFVpvgMdfjqWNw "R – Try It Online")
Outputs one egyptian fractional representation of 1 using n fractions, constructed using [ZaMoC's](https://codegolf.stackexchange.com/a/241226/95126) & [dingledooper's](https://codegolf.stackexchange.com/a/241234/95126) approach.
---
# [R](https://www.r-project.org/), 102 bytes
```
function(n,m=n){while(all(F<-apply(l<-combn(1:m,n),2,function(k)sum(prod(k)/k)-prod(k))))m=m+1;l[,!F]}
```
[Try it online!](https://tio.run/##hY5BCsIwFET3vYW4@R9TSl1JNdtewKVIiTG1pclPSFJKEc8eqxS3zuoNwwzjk3rMLvaCmtYLGXtLjVfOq6Aoio/lqR3pGwAxwwmfU9drBUJrqE@5cE7PoE@5tOZGUFaGEbI9@5UGDKMB5@19wWLAfMVFhptdedQXtqmvrwSCwqQ8/3cIDohZtpWdkkOVeTudRxOgLOI6gJje "R – Try It Online")
A brute-force approach that outputs the egyptian fractional representation(s) with the lowest-valued top denominator, by trying all combinations of fractions up to successively increasing denominators.
[Answer]
# Excel, 47 bytes
```
=LET(x,SEQUENCE(A1),0.75^(x>A1-2)*2^x-(A1=1)/2)
```
[Link to Spreadsheet](https://1drv.ms/x/s!AkqhtBc2XEHJngB37bnH6DTyorgt?e=vJmlht)
Uses the fact that for \$ n>2\$: $$\sum\_{k=1} ^{n-2} \left(\frac 1 {2}\right) ^ k + \frac 4 {3}\left(\left(\frac 1 {2}\right)^{n-1} + \left(\frac 1 {2}\right)^n\right) = 1$$.
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), ~~106~~ ~~105~~ 98 bytes
```
(load library
(d g(q((n x)(i(e n 1)x(g(s n 1)(c(*(a(h x)1)(h x))(c(a(h x)1)(t x
(d f(q((n)(g n(q(1
```
[Try it online!](https://tio.run/##PYwxDoAgEAR7X3HlYkfjf1AELyGoQAGvP4HCamdnky0cW@D8iCDcxlLgPZnUFljyeIFIVYFxUiStKjzyJBxYYXD1tZcRQ/2iUB0Pbj4oeIqdtMDRpuQD "tinylisp – Try It Online")
Not sure there's a better way to ~~get `(1)` than `(c 1()`~~ (use `(q(1`) add two elements to a list than `(c X(c Y Z)`.
Ports e.g., [Dominic van Essen's R answer](https://codegolf.stackexchange.com/a/241249/67312).
Thanks to DLosc for -5 bytes.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
ＦＮ⊞υ⊕∨Πυ¹⊞υ⊖⊟υＩυ
```
[Try it online!](https://tio.run/##RcsxDoMwDEDRnVNktKUwMDBlbBeWkiukwVUqhQSZuNc3pVLF/N@PKXCsIau@KhuYyibtIeuTGBCNlz2BWDOVyLRSabTAzOC5LhIbCFozIKLr/vBOF/R1@4pf5XdpcAv7uaBTHbX/5AM "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Uses a formula for Sylvester's sequence taken from A000058.
```
ＦＮ
```
Loop `n` times...
```
⊞υ⊕∨Πυ¹
```
... push the incremented product of the list to the list. (Note that the version of Charcoal on TIO can't take the product of an empty list, so I have to manually replace the result with `1`.)
```
⊞υ⊖⊟υ
```
Decrement the last element of the list.
```
Ｉυ
```
Output the list.
14 bytes using the newer version of Charcoal on ATO that can take the product of an empty list:
```
ＦＮ⊞υ⊕Πυ⊞υ⊖⊟υＩυ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iOSOxKDk_MWfBgqWlJWm6FjeT0_KLFDQ88wpKS_xKc5NSizQ0NRUCSoszNEp1FDzzkotSc1PzSlJTNAKK8lNKk0s0SjU1Na25YCpcUpFU5BfAZIsy80o0nBOLwcqtlxQnJRdDLdwUraRblqOko6CkmwkiTZVioTIA "Charcoal – Attempt This Online") Link is to verbose version of code.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~10~~ 9 bytes
```
⁸P‘ṭƊ¡’0¦
```
[Try it online!](https://tio.run/##AR4A4f9qZWxsef//4oG4UOKAmOG5rcaKwqHigJkwwqb//zQ "Jelly – Try It Online")
Based on the Sylvester sequence.
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), ~~156~~ ~~97~~ 91 bytes
*-59 bytes remove extra spaces and use pow function*
*-6 bytes thanks to @DLosc*
```
(load library
(d g(q((n m)(i m(c(/(*(s 4(l(s n 2)m))(pow 2 m))4)(g n(s m 1)))(
q((n)(g n n
```
[Try it online!](https://tio.run/##Hcw7CoAwEITh3lNMOWvjEzyPGpRAsj5BPH1c0/zNN8zt9Q3@2lNi2EaH4KdzPN@CDisPUhGFHpEzK5a80DNYFa1EEe7bg9Ym0gtXqElEIwb/wZIPMkATFxNYu9wht6klfQ "tinylisp – Try It Online")
## First Attempt
```
(load library
(d p(q((x n)(i n(* x(p x(s n 1)))1
(d g(q((n m)(i m(c(/(*(i(l m (s n 1))4 3)(p 2 m))4)(g n(s m 1)))(
(d f(q((n)(g n n
```
[Try it online!](https://tio.run/##bYyxDoMwDER3vuLGM0ubwg/RIlCkxATSAb4@dSKx1ZZvuef39XoFn1MpDNs0I/j3MR1XxxmJO3lChR7KHieTXYbCiYiryFoRRaxI5IcP9vQMiLi5EYPY38sYGYWrmbLV1cBqWJqhFbZ/pwMKF3uB5dDSPaX8AA "tinylisp – Try It Online")
Porting into tinylisp.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 34 bytes
```
n->[q-(i==n)|i<-[a=1..n],a*=q=1+a]
```
[Try it online!](https://tio.run/##FcdBCoMwEAXQq3xcJe2MELStC8eLhCxmowTKMEo3Qu8e2917rkflzdsKacZL3jlUEYvfOnNWSX1vhfQmu6S7lqbu7zMYeIEf1T4/dv90WIPFSMiJMBBGwoPwJLwIU4ntAg "Pari/GP – Try It Online")
A port of [@ZaMoC's Mathematica answer](https://codegolf.stackexchange.com/a/241226/9288) and [@G B's Ruby answer](https://codegolf.stackexchange.com/a/241229/9288).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~13~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
$GD>DŠ*})
```
-4 bytes porting [*@GB*'s Ruby answer](https://codegolf.stackexchange.com/a/241229/52210).
[Try it online](https://tio.run/##yy9OTMpM/f9fxd3FzuXoAq1azf//TQE) or [verify the first \$n=10\$ test cases, excluding \$2\$](https://tio.run/##yy9OTMpM/R/iY@RdVmmvpPCobZKCkv1/w0p3FzuXowu0ajX/6/wHAA).
Alternative 9-byter inspired by *@Neil*'s comment below, which is pretty similar as the current approach above:
```
$EPNIÊ+ˆ¯
```
[Try it online](https://tio.run/##yy9OTMpM/f9fxTXAz/Nwl/bptkPr//83BQA) or [verify the first \$n=10\$ test cases, excluding \$2\$](https://tio.run/##yy9OTMpM/R/iY@RdVmmvpPCobZKCkv1/w0rXAL/Kw13ap9sOrf9fq3Noy38A).
**Explanation:**
```
$         # Push 1 and the input-integer
 G        # Loop input-1 amount of times:
  D       #  Duplicate the current integer
   >      #  Increase this copy by 1
    D     #  Duplicate that as well
     Š    #  Tripleswap the stack from a,b,c to c,a,b
      *   #  Multiply the top two values
 })       # After the loop, wrap all values on the stack into a list
          # (after which the result is output implicitly)
$         # Push 1 and the input-integer
 E        # Loop `N` in the range [1,input]:
  P       #  Push the product of the stack / top
          #  (which will be 1 in the first iteration)
   NIÊ    #  Check that `N` is NOT equal to the input
          #  (0 if it's the final iteration, 1 otherwise)
      +   #  Add that to the product
       ˆ  #  Pop and add it to the global array
        ¯ #  Push the global array for the next iteration
          # (after which the last pushed global array is output implicitly after
          # the loop)
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~53~~ 52 bytes
```
f=(n,x=1)=>[,[x],[x*3,x*1.5]][n]||[x*=2,...f(n-1,x)]
```
[Try it online!](https://tio.run/##DcjBDoIwDADQ32mhNFbjac4fWXogyEwNWQ0QswP/Pjm8y/uMv3GbVvvuQ/HX3FqOUKhGwfhMlKqeuhvVTviumooexxnxSsycoQxCFbWF7CtYlGAPuYS@N5y8bL7MvPgbjDIYYmh/ "JavaScript (Node.js) – Try It Online")
Making special \$1=\frac 13+\frac 1{1.5}\$ make it bit shorter
[Answer]
# [Python 2](https://docs.python.org/2/), 43 bytes
*-10 bytes thanks to dingledooper*
```
lambda n:[4-(x>n-3)<<x>>1for x in range(n)]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKtpEV6PCLk/XWNPGpsLOzjAtv0ihQiEzT6EoMS89VSNPM/Y/SCgPIWSoo2BoqGmlUFCUmVeikKejkAZU9R8A "Python 2 – Try It Online")
## First Attempt, 53 bytes
```
f=lambda n:map(lambda x:2**x*(4-(x>n-3))/2, range(n))
```
[Try it online!](https://tio.run/##LcpBCoAgEEbhq8zSEaOyVkLdZaKsIH9FWtjprUXL9/HScx8RtlY/XRKWVQguSFJ/FGe1LlqNjSozmoG5tYayYN8UmKuPmUAnfuoN9R07SvnETTDkv6u@ "Python 2 – Try It Online")
Porting to Python.
[Answer]
# JavaScript, 48 bytes
[Try it online](https://tio.run/##Dck7DoMwDADQ68QlseoiFtKkB0EZIj6RK2ojqCpunzK86b3zLx/jztvXiU5zrSVIiM5JpNdAFhGLEUj4yZs5QzxvD@jlGuxsm/qBUvWL7oYDeX7S3TcNw6hy6DrjqsWwvQD4@gc "JavaScript (Node.js) – Try It Online")
```
f=n=>--n>1?[1,...f(n)].map(x=>x*2):n?[1.5,3]:[1]
```
Original answer (49 bytes):
```
f=n=>[[1],,[2,3,6]][--n]||[2,...f(n).map(x=>x*2)]
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 26 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{1≡⍵:1⋄3≡⍵:2 3 6⋄2,2×∇⍵-1}
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=qzZ81LnwUe9WK8NH3S3GULaRgrGCGZBvpGN0ePqjjnagmK5hLQA&f=Szu0wlDBWMFEwRQA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
A dfn submission which encodes the inductive proof posted in the comments: to get a solution for `n+1`, double each of the denominators and add `2` to the denominators.
E.g. `2 3 6` solves `3` → `2 4 6 12` solves `4` → `2 4 8 12 24` solves `5` → ...
[Answer]
# [Scala](https://www.scala-lang.org/), 105 bytes
Golfed version. [Try it online!](https://tio.run/##ZU87T8MwEN77Kz5ZHWzillq8U1wJFlSJAaliAoRMmhRD4iS2WxVF@e3BSSsWlrvT3fc6l6hcdeXHV5p4PCmrH6qlWfVLNCNgnWYolDZU2Y2LcWet@nlZeavN5o3FeDbaQw5IYKdyaFNt/aN2/bZvVHCccZxzXHBcclxxXHPccIgZGw2sP8Y0K22qkk80MJCL4QhUwcrnhjoyNnDbolBm7WLC/p1FcBw3GTVsWqiK7uWCiFMSRfupLw@BWfF9GChBBMJavJqjUBtq2/XPBoF4aTyTVMCXOKppuWh2ykLxWt7rTQBQIgibh8j0/XYyQDVr1Ims57UUkWrn9YTqLBClYQJp7lLMWMv6MGndtd0v)
```
def f(n:Int)=(1 to n).map(i=>{var a,q=BigInt("1");for(_<-1 to i){a*=q;q=1+a};q-(if(i==n)1 else 0)}).toSeq
```
Ungolfed version. [Try it online!](https://tio.run/##ZU9dS8MwFH3vrziEPSQumyt@FzvQFxn4IAyf5pC4tTPapl2Sjcnob@@SttYHA5fkntxz7jlmJTJR18XHV7KyeBFaPpUzNfcojgGwTlLkQioq9MZEeNBa/CzmVku1WbIIr0paxM0ksBcZpCp39lkaj/qLhhwXHJccVxzXHDcctxx3HOGEBQ2rZ4zTQidi9YkjFOJp8wmUbpXNFDVkoGB2eS7U2kSE/fsO3cbBMaWKjXNR0kM8JeE5GQ4PY1u0hln@3T4owRCEVXhTnVAV@OryOo0IM2VdPu9r8Sg3rlv2OWkIW6Dd48zKP7N7oSH41k22HErC3qlLB/qO@xEaumSdmj8CZzG2fesFQmdRdEgV/OIjUJm6Qhw7A24oyUyCSRfCJfWGmyxVUNcn)
```
object PariGpInScala {
  def main(args: Array[String]): Unit = {
    val inputList = List(1, 3, 4, 5, 6, 7, 8, 9, 10)
    inputList.foreach { n =>
      println(s"$n summands:")
      println(s"1 = ${f(n).map(x=>"1/"++x.toString)mkString(" + ")} \n")
    }
  }
  def f(n: Int): List[BigInt] = {
    (1 to n).map { i =>
      var a,q = BigInt("1")
      for (_ <- 1 to i) {
        a *= q
        q = 1 + a
      }
      q - (if (i == n) 1 else 0)
    }.toList
  }
}
```
]