How to resolve the algorithm Duffinian numbers step by step in the Mathematica/Wolfram Language programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Duffinian numbers step by step in the Mathematica/Wolfram Language 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 Mathematica/Wolfram Language programming language

This code defines a function called DuffianQ that takes an integer n as input and checks if it is a Duffian number. A Duffian number is a composite (non-prime) number such that the sum of its divisors is coprime with the number itself.

The code first clears any previously defined symbols with the name DuffianQ using ClearAll[DuffianQ].

The function DuffianQ is then defined as follows:

DuffianQ[n_Integer] := CompositeQ[n] \[And] CoprimeQ[DivisorSigma[1, n], n]

Here, CompositeQ[n] checks if n is a composite number (not prime), and CoprimeQ[DivisorSigma[1, n], n] checks if the sum of the divisors of n (excluding 1 and n itself) is coprime with n.

Next, the code uses the function Select[DuffianQ][Range[1000000]] to find all Duffian numbers up to 1 million. The result is stored in the variable dns.

The code then takes the first 50 Duffian numbers from the list dns using Take[dns, UpTo[50]].

The code then defines a function called triplets that takes a list of Duffian numbers as input and returns a list of strings, where each string consists of two Duffian numbers separated by a dash. The function uses the ToString function to convert the Duffian numbers to strings, and the \[LongDash] symbol to represent the dash.

The code then uses the SequencePosition function to find all occurrences of the pattern {1, 1} in the list of differences between consecutive Duffian numbers in dns. The result is a list of positions, which is then used to extract the corresponding triplets of Duffian numbers.

Finally, the code uses the Multicolumn function to display the list of triplets in a table with 5 columns and an automatic width for each column. The Appearance -> "Horizontal" option is used to display the table horizontally.

Source code in the wolfram programming language

ClearAll[DuffianQ]
DuffianQ[n_Integer] := CompositeQ[n] \[And] CoprimeQ[DivisorSigma[1, n], n]
dns = Select[DuffianQ][Range[1000000]];
Take[dns, UpTo[50]]
triplets = ToString[dns[[#]]] <> "\[LongDash]" <> ToString[dns[[# + 2]]] & /@ SequencePosition[Differences[dns], {1, 1}][[All, 1]]
Multicolumn[triplets, {Automatic, 5}, Appearance -> "Horizontal"]


  

You may also check:How to resolve the algorithm Run-length encoding step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Nonogram solver step by step in the Julia programming language
You may also check:How to resolve the algorithm Product of min and max prime factors step by step in the Julia programming language
You may also check:How to resolve the algorithm Special characters step by step in the 360 Assembly programming language