#!/usr/bin/env perl use utf8; ############################################################################### # This program computes the number of primes function π(x) # using an estimate formula. # # Copyright © 2021 Richard Lesh. All rights reserved. ############################################################################### use POSIX qw(floor); use Utils; use strict; use warnings; sub π { my ($x) = @_; return floor($x / (log($x) - 1.0) + 0.5); } MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); my $x = 10; for (my $i = 2; $i <= 9; ++$i) { $x *= 10; print Utils::messageFormat("π(\{0:d\}) = \{1:d\}", $x, π($x)), "\n"; } }