How to resolve the algorithm Amicable pairs step by step in the Transd programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the Transd 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 Transd programming language
Source code in the transd programming language
#lang transd
MainModule : {
_start: (lambda
(with sum 0 d 0 f Filter( from: 1 to: 20000 apply: (lambda
(= sum 1)
(for i in Range(2 (to-Int (sqrt @it))) do
(if (not (mod @it i))
(= d (/ @it i)) (+= sum i)
(if (neq d i) (+= sum d))))
(ret sum)))
(with v (to-vector f)
(for i in v do
(if (and (< i (size v))
(eq (+ @idx 1) (get v (- i 1)))
(< i (get v (- i 1))))
(textout (+ @idx 1) ", " i "\n")
)))))
}
You may also check:How to resolve the algorithm Bitwise operations step by step in the Retro programming language
You may also check:How to resolve the algorithm Find the intersection of two lines step by step in the Wren programming language
You may also check:How to resolve the algorithm Function frequency step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Text processing/1 step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the RPL programming language