8

1

Let $N(n)$ be a set of integers, which can be presented using first $n$ Egyptian fractions:

$$ N(n):=\{m\in\mathbb{Z}:\ \ m=\sum_{i=1}^n\frac{\epsilon_i}{i},\ \epsilon_i=0\ \text{or}\ 1\} $$

I want to write a code in **Mathematica** that gives $N(n)$, but I think `A[e,n]`

does not define what I need above: for example

```
A[e_,n_]:=Sum[e/i,{e,0,1},{i,1,n}];
n=1000;
Sum[If[IntegerQ[A[e,n]]==True,m,0],{m,1,10}]
```

Thanks.

P.S. example

\begin{align} 0=&0\\ 1=&1\\ 2=&1+\frac12+\frac13+\frac04+\frac05+\frac16 \end{align} therefore $N(6)=\{0,1,2\}$

`A[e,n]`

does not depend on`e`

. So you can use`A[n_]:=...`

Otherwise it looks good. – Sumit – 2017-11-26T08:50:34.533Your

`A`

function takes`e == 0`

and runs through all the`i`

-values, and then takes`e == 1`

and runs through all the`i`

-values, giving`0/1 + 0/2 + ... + 0/n + 1/1 + 1/2 + ... + 1/n`

. Try`Table[{e, i}, {e, 0, 1}, {i, 1, 6}]`

to see what the indices are doing. – aardvark2012 – 2017-11-26T10:49:57.820Doesn't N(n) always contain 0? For example, for N(6), 0 = 0/1 + 0/2 + 0/3 + 0/4 + 0/5 + 0/6. – evanb – 2017-11-26T16:23:24.463

1A solution that scales (very, very) poorly is

`Union[Select[Total /@ Subsets[1/Range[6]], IntegerQ]]`

(for n=6, for example). – evanb – 2017-11-26T16:26:52.137You can brute force it for $n \lesssim 25$. Will that work, or are you really interested in $n=1000$? – Carl Woll – 2017-11-26T16:31:42.050

2I changed the title to make the question to be more attractive. I hope, you don't mind. – ybeltukov – 2017-11-26T21:44:39.093

@evanb, thanks, I corrected. Also I like to have representation for each of them in

outputas you see in P.S. – asad – 2017-11-27T05:39:41.9271Straight-forward method using

`Solve`

(and not suffering from exponential memory usage) would be something like this:`n0 /. (With[{n = 50}, Solve[{Sum[a[i]/i, {i, n}] == n0, Array[a, n] \[Element] Cuboid[ConstantArray[0, n]]}, {n0}, Integers]] /. ConditionalExpression[v_, ___] :> v) (* {0, 1, 2, 3} *)`

... this doesn't solve the exponential time complexity, though. – kirma – 2017-11-27T06:39:33.0602

This problem is essentially the same as computing the OEIS sequence A101877. With a little bit of cleverness one can search the values up to at least 300 (which would correspond with $N(300)={0,1,2,3,4,5}$), just by using straight-forward

– kirma – 2017-11-29T07:19:06.137`Solve`

and constraints on the problem size based on solutions already found. Going up to the sum corresponding to 6 (at 469) might be infeasible using this method (probably takes at least several days of computing time, possibly a lot more).