require "bignum" local sylvester = {bigint.two} mpz.init() -- use GMP mpq.init() local a = mpz.set(1, 2) local count = 1 while true do local next = mpz.get(a) + 1 sylvester:insert(next) count += 1 if count == 10 then break end mpz.mul(a, next) end mpz.clear(a) print("The first 10 terms in the Sylvester sequence are:") print(sylvester:mapped(|e| -> e:tostring()):concat("\n")) a = mpq.set(a, 0) for sylvester as s do mpq.add(a, bigrat.recip(s)) end local sum_recip = mpq.get(a) mpq.clear(a) print("\nThe sum of their reciprocals as a rational number is:") print(sum_recip) print("\nThe sum of their reciprocals as a decimal number (to 211 places) is:") print(sum_recip:todecimal(211))