How to resolve the algorithm Duffinian numbers step by step in the MAD programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Duffinian numbers step by step in the MAD programming language
Table of Contents
Problem Statement
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k.
161 is a Duffinian number.
Duffinian numbers are very common. It is not uncommon for two consecutive integers to be Duffinian (a Duffinian twin) (8, 9), (35, 36), (49, 50), etc. Less common are Duffinian triplets; three consecutive Duffinian numbers. (63, 64, 65), (323, 324, 325), etc. Much, much less common are Duffinian quadruplets and quintuplets. The first Duffinian quintuplet is (202605639573839041, 202605639573839042, 202605639573839043, 202605639573839044, 202605639573839045). It is not possible to have six consecutive Duffinian numbers
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Duffinian numbers step by step in the MAD programming language
Source code in the mad programming language
NORMAL MODE IS INTEGER
DIMENSION SIGMA(10000),OUTROW(10)
INTERNAL FUNCTION(AA,BB)
ENTRY TO GCD.
A = AA
B = BB
STEP WHENEVER A.E.B, FUNCTION RETURN A
WHENEVER A.G.B, A = A-B
WHENEVER A.L.B, B = B-A
TRANSFER TO STEP
END OF FUNCTION
INTERNAL FUNCTION(N)
ENTRY TO DUFF.
SIG = SIGMA(N)
FUNCTION RETURN SIG.G.N+1 .AND. GCD.(N,SIG).E.1
END OF FUNCTION
INTERNAL FUNCTION(N)
ENTRY TO TRIP.
FUNCTION RETURN DUFF.(N) .AND.
0 DUFF.(N+1) .AND. DUFF.(N+2)
END OF FUNCTION
THROUGH SZERO, FOR I=1, 1, I.G.10000
SZERO SIGMA(I) = 0
THROUGH SCALC, FOR I=1, 1, I.G.10000
THROUGH SCALC, FOR J=I, I, J.G.10000
SCALC SIGMA(J) = SIGMA(J) + I
PRINT COMMENT $ FIRST 50 DUFFINIAN NUMBERS$
CAND = 0
THROUGH DUFROW, FOR R=0, 1, R.GE.5
THROUGH DUFCOL, FOR C=0, 1, C.GE.10
SCHDUF THROUGH SCHDUF, FOR CAND=CAND+1, 1, DUFF.(CAND)
DUFCOL OUTROW(C) = CAND
DUFROW PRINT FORMAT ROWFMT,OUTROW(0),OUTROW(1),OUTROW(2),
0 OUTROW(3),OUTROW(4),OUTROW(5),OUTROW(6),
1 OUTROW(7),OUTROW(8),OUTROW(9)
PRINT COMMENT $ $
PRINT COMMENT $ FIRST 15 DUFFINIAN TRIPLETS$
CAND = 0
THROUGH DUFTRI, FOR S=0, 1, S.GE.15
SCHTRP THROUGH SCHTRP, FOR CAND=CAND+1, 1, TRIP.(CAND)
DUFTRI PRINT FORMAT TRIFMT,CAND,CAND+1,CAND+2
VECTOR VALUES ROWFMT = $10(I5)*$
VECTOR VALUES TRIFMT = $3(I7)*$
END OF PROGRAM
You may also check:How to resolve the algorithm Copy a string step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Assertions step by step in the Python programming language
You may also check:How to resolve the algorithm Hamming numbers step by step in the PureBasic programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the Swift programming language
You may also check:How to resolve the algorithm Determine if a string has all unique characters step by step in the Java programming language