How to resolve the algorithm Amicable pairs step by step in the Arturo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the Arturo 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 Arturo programming language
Source code in the arturo programming language
properDivs: function [x] ->
(factors x) -- x
amicable: function [x][
y: sum properDivs x
if and? x = sum properDivs y
x <> y
-> return @[x,y]
return ø
]
amicables: []
loop 1..20000 'n [
am: amicable n
if am <> ø
-> 'amicables ++ @[sort am]
]
print unique amicables
You may also check:How to resolve the algorithm Averages/Mode step by step in the Clojure programming language
You may also check:How to resolve the algorithm MD5 step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Lasso programming language
You may also check:How to resolve the algorithm Substitution cipher step by step in the jq programming language
You may also check:How to resolve the algorithm Kronecker product based fractals step by step in the Factor programming language