How to resolve the algorithm Amicable pairs step by step in the Perl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the Perl programming language
Table of Contents
Problem Statement
Two integers
N
{\displaystyle N}
and
M
{\displaystyle M}
are said to be amicable pairs if
N ≠ M
{\displaystyle N\neq M}
and the sum of the proper divisors of
N
{\displaystyle N}
(
s u m
(
p r o p D i v s
( N ) )
{\displaystyle \mathrm {sum} (\mathrm {propDivs} (N))}
)
= M
{\displaystyle =M}
as well as
s u m
(
p r o p D i v s
( M ) )
N
{\displaystyle \mathrm {sum} (\mathrm {propDivs} (M))=N}
.
1184 and 1210 are an amicable pair, with proper divisors:
Calculate and show here the Amicable pairs below 20,000; (there are eight).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Amicable pairs step by step in the Perl programming language
Source code in the perl programming language
use ntheory qw/divisor_sum/;
for my $x (1..20000) {
my $y = divisor_sum($x)-$x;
say "$x $y" if $y > $x && $x == divisor_sum($y)-$y;
}
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Batch File programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the Go programming language
You may also check:How to resolve the algorithm Time a function step by step in the Ada programming language
You may also check:How to resolve the algorithm Date format step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Loops/For step by step in the ERRE programming language