How to resolve the algorithm Untouchable numbers step by step in the Perl programming language
How to resolve the algorithm Untouchable numbers step by step in the Perl programming language
Table of Contents
Problem Statement
All untouchable numbers > 5 are composite numbers. No untouchable number is perfect. No untouchable number is sociable. No untouchable number is a Mersenne prime. No untouchable number is one more than a prime number, since if p is prime, then the sum of the proper divisors of p2 is p + 1. No untouchable number is three more than an odd prime number, since if p is an odd prime, then the sum of the proper divisors of 2p is p + 3. The number 5 is believed to be the only odd untouchable number, but this has not been proven: it would follow from a slightly stronger version of the Goldbach's conjecture, since the sum of the proper divisors of pq (with p, q being distinct primes) is 1 + p + q. There are infinitely many untouchable numbers, a fact that was proven by Paul Erdős. According to Chen & Zhao, their natural density is at least d > 0.06.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Untouchable numbers step by step in the Perl programming language
Source code in the perl programming language
use strict;
use warnings;
use enum qw(False True);
use ntheory qw/divisor_sum is_prime/;
sub sieve {
my($n) = @_;
my %s;
for my $k (0 .. $n+1) {
my $sum = divisor_sum($k) - $k;
$s{$sum} = True if $sum <= $n+1;
}
%s
}
my(%s,%c);
my($max, $limit, $cnt) = (2000, 1e5, 0);
%s = sieve 14 * $limit;
!is_prime($_) and $c{$_} = True for 1..$limit;
my @untouchable = (2, 5);
for ( my $n = 6; $n <= $limit; $n += 2 ) {
push @untouchable, $n if !$s{$n} and $c{$n-1} and $c{$n-3};
}
map { $cnt++ if $_ <= $max } @untouchable;
print "Number of untouchable numbers ≤ $max : $cnt \n\n" .
(sprintf "@{['%6d' x $cnt]}", @untouchable[0..$cnt-1]) =~ s/(.{84})/$1\n/gr . "\n";
my($p, $count) = (10, 0);
my $fmt = "%6d untouchable numbers were found ≤ %7d\n";
for my $n (@untouchable) {
$count++;
if ($n > $p) {
printf $fmt, $count-1, $p;
printf($fmt, scalar @untouchable, $limit) and last if $limit == ($p *= 10)
}
}
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Python programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Ruby programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Quackery programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the PHP programming language