program Project1; {$APPTYPE CONSOLE} uses SysUtils, Windows; function calc(x1, y1, x2, y2: Real; Depth: Integer): Real; var x, y: Real; begin if x1 * x1 + y1 * y1 >= 1 then Result := 0 else if x2 * x2 + y2 * y2 <= 1 then Result := (x2-x1)*(y2-y1) else if Depth <= 0 then Result := (x2-x1)*(y2-y1) / 2 else begin x := (x1 + x2) / 2; y := (y1 + y2) / 2; Result := calc(x1, y1, x , y , Depth-1) + calc(x1, y , x , y2, Depth-1) + calc(x , y1, x2, y , Depth-1) + calc(x , y , x2, y2, Depth-1) ; end; end; function getpi: Real; begin Result := calc(0,0,1,1,27) * 4; end; var ct: Cardinal; pi: Real; begin ct := GetTickCount; pi := getpi; Writeln('pi=', pi, ' time=', GetTickCount-ct, 'ms'); end.