Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
26
Task/Sylvesters-sequence/Pluto/sylvesters-sequence.pluto
Normal file
26
Task/Sylvesters-sequence/Pluto/sylvesters-sequence.pluto
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue