How to resolve the algorithm Amicable pairs step by step in the Frink programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the Frink 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 Frink programming language
Source code in the frink programming language
n = 1
seen = new set
do
{
n = n + 1
if seen.contains[n]
next
sum = sum[allFactors[n, true, false, false]]
if sum != n and sum[allFactors[sum, true, false, false]] == n
{
println["$n, $sum"]
seen.put[sum]
}
} while n <= 20000
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Nim programming language
You may also check:How to resolve the algorithm Make directory path step by step in the Perl programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the Lua programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the Perl programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the Icon and Unicon programming language