Sylvester's sequence: Difference between revisions
Content added Content deleted
Line 222: | Line 222: | ||
Sum of reciprocals of first 10: 0.9999999999999999999999999999999999999999999999999999999999999999999999999999914 |
Sum of reciprocals of first 10: 0.9999999999999999999999999999999999999999999999999999999999999999999999999999914 |
||
</pre> |
</pre> |
||
=={{header|Nim}}== |
|||
{{libheader|bignum}} |
|||
<lang Nim>import sequtils |
|||
import bignum |
|||
proc sylverster(lim: Positive): seq[Int] = |
|||
result.add(newInt(2)) |
|||
for _ in 2..lim: |
|||
result.add result.foldl(a * b) + 1 |
|||
let list = sylverster(10) |
|||
echo "First 10 terms of the Sylvester sequence:" |
|||
for item in list: echo item |
|||
var sum = newRat() |
|||
for item in list: sum += newRat(1, item) |
|||
echo "\nSum of the reciprocals of the first 10 terms: ", sum.toFloat</lang> |
|||
{{out}} |
|||
<pre>First 10 terms of the Sylvester sequence: |
|||
2 |
|||
3 |
|||
7 |
|||
43 |
|||
1807 |
|||
3263443 |
|||
10650056950807 |
|||
113423713055421844361000443 |
|||
12864938683278671740537145998360961546653259485195807 |
|||
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 |
|||
Sum of the reciprocals of the first 10 terms: 0.9999999999999999</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |