How to resolve the algorithm Amicable pairs step by step in the Oforth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the Oforth 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 Oforth programming language
Source code in the oforth programming language
import: mapping
Integer method: properDivs -- []
#[ self swap mod 0 == ] self 2 / seq filter ;
: amicables
| i j |
Array new
20000 loop: i [
i properDivs sum dup ->j i <= if continue then
j properDivs sum i <> if continue then
[ i, j ] over add
]
;
You may also check:How to resolve the algorithm String concatenation step by step in the C++ programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Retro programming language
You may also check:How to resolve the algorithm Leap year step by step in the ERRE programming language
You may also check:How to resolve the algorithm Sequence: smallest number with exactly n divisors step by step in the J programming language
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the Icon and Unicon programming language