#!/usr/bin/perl # Copyright 2004 by Richard Mansfield Kandarian # This program is licensed under the GPL. The GPL text is available at # http://www.opensource.org/licenses/gpl-license.php $sum1 = $sum2 = 2; for $n (2..$ARGV[0]-1){ $dn = $n+1; $t = 1 + 2*$n/$dn; $sum1 += $t; $sum2 += $t; my $d = 1/$n + 1/($dn); my $m = 2; my $c = 1; my $nc; CHECK: while(1){ if(($nc = $d*($m-1)+1/$m) < $c){ $c = $nc; $m++; next CHECK; }else{ last CHECK; } } if($c < 1){ $sum2 -= 1 - $c; } printf("%6s: %20s, % 3.6s, %3s, %20s, % 3.6s\n", $n+1, $sum1, $sum1/($n+1), $m, $sum2, $sum2/($n+1)); }