Data Update
This commit is contained in:
parent
015c2add84
commit
e50b5c3114
206 changed files with 6337 additions and 523 deletions
27
Task/Sylvesters-sequence/Pascal/sylvesters-sequence.pas
Normal file
27
Task/Sylvesters-sequence/Pascal/sylvesters-sequence.pas
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
program SylvesterSeq;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses SysUtils,
|
||||
UIntX; // in the library IntX4Pascal
|
||||
(*
|
||||
As noted in the Wikipedia article "Sylvester's sequence", we have
|
||||
1/2 + 1/3 + ... + 1/s[j-1] = (s[j] - 2)/(s[j] - 1),
|
||||
so that instead of summing the reciprocals explicitly we can just
|
||||
calculate an extra term.
|
||||
*)
|
||||
var
|
||||
s : UIntX.TIntX; // arbitrarily large integer
|
||||
i : integer;
|
||||
begin
|
||||
s := 1;
|
||||
for i := 0 to 9 do begin
|
||||
inc(s);
|
||||
WriteLn( SysUtils.Format( 's[%d] = %s', [i, s.ToString]));
|
||||
s := s*(s - 1);
|
||||
end;
|
||||
WriteLn( 'Sum of reciprocals =');
|
||||
WriteLn( (s - 1).ToString);
|
||||
WriteLn( '/'); // on a separate line for clarity
|
||||
WriteLn( s.ToString);
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue