# Mathematica never seems to stop

Find $$a$$,$$b$$ if $$\frac{1}{a}+\frac{1}{b}=\frac{1}{2008}$$, where $$a$$ and $$b$$ are positive integers.

When I set the Range to 10 000, Mathematica never seems to stop.

When I set the Range to 1000 000, there was insufficient memory available to complete the computation.

list1 = Range[10000];
f[{a_, b_}] := 1/a + 1/b;
Pick[Tuples[list1, 2], f[#] & /@ Tuples[list1, 2], 1/2008]


Is there anyone who can solve this fuss? I have 16GB of RAM. I thought that is enough to find the answer below 10000

• Have you tried evaluating Reduce[1/a + 1/b == 2008 && a > 0 && b > 0, {a, b}, Integers]? Commented May 27, 2020 at 10:37
• @J.M., I just try your method , but only get False.
– kile
Commented May 27, 2020 at 10:42
• Are you sure your problem isn't $1/a + 1/b = 1/2008$? I've seen this sort of a problem being mentioned in that form somewhere recently... (and you can find all solutions to that problem with Solve[1/a + 1/b == 1/2008 && 0 < a <= b, {a, b}, Integers]. Commented May 27, 2020 at 10:45
• @kirma which forum are you talking about? Can you provide me a link or something else?
– kile
Commented May 27, 2020 at 10:47
• @kile It was probably this: math.stackexchange.com/questions/3123923/… - nonetheless, largest number you can form with positive integers on $1/a + 1/b$ is $2$ when assigning $1$ to both $a$ and $b$... Commented May 27, 2020 at 10:51

This works but is a terrible way of solving the problem:

list1 = Range[10000];
f[{a_, b_}] = 1/a + 1/b;
Select[Tuples[list1, 2], f[#] == 1/2008 &]

(*    {{3012, 6024}, {4016, 4016}, {6024, 3012}}    *)

• How long does it take for your computer to find out the results? My computer runs for 5 mins and still can't return a result even if I used your code.
– kile
Commented May 27, 2020 at 11:36
• @kile Tuples creates a big list, which can easily cause your machine to run out of RAM, which makes this drastically slower. 16 GB of RAM is not enough to do this comfortably. There's also experimental function called SubsetCases in v12.1 but it doesn't really scale well to such large sets. Commented May 27, 2020 at 13:42
• @Roman How much RAM does it need? My PC just locks on it. Is there a way to solve it, in smaller pieces? I suppose it is an all (10000) or nothing question? Commented May 27, 2020 at 14:22
• Tuples[list1, 2] // ByteCount gives 1600000208 which is 1.6 GB, shouldn't be a problem. Commented May 27, 2020 at 14:41
• As I said this is a terrible way of solving your problem. Use Solve or iterate over the lists without storing them or ... Commented May 27, 2020 at 14:42

This way seems to be pretty quick:

Solve[1/a + 1/b == 1/2008, b]
(*{{b -> (2008 a)/(a - 2008)}}*)

Reduce[b == (2008 a)/(a - 2008) && 0 < a < b && a ∈ Integers && b ∈ Integers]

(*(a == 2009 && b == 4034072) || (a == 2010 &&
b == 2018040) || (a == 2012 && b == 1010024) || (a == 2016 &&
b == 506016) || (a == 2024 && b == 254012) || (a == 2040 &&
b == 128010) || (a == 2072 && b == 65009) || (a == 2259 &&
b == 18072) || (a == 2510 && b == 10040) || (a == 3012 &&
b == 6024)*)

• Also FindInstance[a*b == 2008 (a + b), {a, b}, Integers, 6] if you just want 6 solutions for example. Commented May 27, 2020 at 21:09