How to resolve the algorithm Amicable pairs step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Amicable pairs step by step in the VBScript 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 VBScript programming language
Source code in the vbscript programming language
start = Now
Set nlookup = CreateObject("Scripting.Dictionary")
Set uniquepair = CreateObject("Scripting.Dictionary")
For i = 1 To 20000
sum = 0
For n = 1 To 20000
If n < i Then
If i Mod n = 0 Then
sum = sum + n
End If
End If
Next
nlookup.Add i,sum
Next
For j = 1 To 20000
sum = 0
For m = 1 To 20000
If m < j Then
If j Mod m = 0 Then
sum = sum + m
End If
End If
Next
If nlookup.Exists(sum) And nlookup.Item(sum) = j And j <> sum _
And uniquepair.Exists(sum) = False Then
uniquepair.Add j,sum
End If
Next
For Each key In uniquepair.Keys
WScript.Echo key & ":" & uniquepair.Item(key)
Next
WScript.Echo "Execution Time: " & DateDiff("s",Start,Now) & " seconds"
You may also check:How to resolve the algorithm Strip comments from a string step by step in the zkl programming language
You may also check:How to resolve the algorithm Function prototype step by step in the Delphi programming language
You may also check:How to resolve the algorithm Knapsack problem/Bounded step by step in the Wren programming language
You may also check:How to resolve the algorithm Statistics/Basic step by step in the C programming language
You may also check:How to resolve the algorithm Additive primes step by step in the Maxima programming language