How to resolve the algorithm Chernick's Carmichael numbers step by step in the Mathematica / Wolfram Language programming language
How to resolve the algorithm Chernick's Carmichael numbers step by step in the Mathematica / Wolfram Language programming language
Table of Contents
Problem Statement
In 1939, Jack Chernick proved that, for n ≥ 3 and m ≥ 1: is a Carmichael number if all the factors are primes and, for n > 4, m is a multiple of 2^(n-4).
For n = 5, the smallest number m that satisfy Chernick's conditions, is m = 380, therefore U(5, 380) is the smallest Chernick's Carmichael number with 5 prime factors. U(5, 380) is a Chernick's Carmichael number because m = 380 is a multiple of 2^(n-4), where n = 5, and the factors { (6380 + 1), (12380 + 1), (18380 + 1), (36380 + 1), (72*380 + 1) } are all prime numbers.
For n ≥ 3, let a(n) be the smallest Chernick's Carmichael number with n prime factors.
Note: it's perfectly acceptable to show the terms in factorized form:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chernick's Carmichael numbers step by step in the Mathematica / Wolfram Language programming language
Description
This Wolfram code implements the algorithm for finding the first Chernick-Carmichael number of a given order, i.e., the smallest number with a specified number of distinct prime factors.
Functions
-
PrimeFactorCounts[n]
calculates the total number of distinct prime factors of the integern
. -
U[n, m]
is a polynomial formula used to generate candidate numbers. -
FindFirstChernickCarmichaelNumber[n]
is the main function for finding the first Chernick-Carmichael number of a specified ordern
.
Algorithm (Inside FindFirstChernickCarmichaelNumber
Function)
-
Initialization:
- Set
step
to an initial search increment. - Set
i
to the starting value for the search. - Set
formula
to theU
polynomial withm
as the variable. - Print a progress indicator dynamically.
- Set
-
Search Loop:
- While
True
:- Calculate
value
by substitutingi
form
informula
. - Check if
value
has the correct number of distinct prime factors (PrimeFactorCounts[value] == n
).- If yes, break out of the loop.
- If no, increment
i
bystep
.
- Calculate
- While
-
Return Result:
- Return the pair
{i, value}
, wherei
is the firstm
value that produces a number with the correct number of prime factors, andvalue
is that number.
- Return the pair
Example Usage
The code is used to find the first Chernick-Carmichael number for orders 3 to 9:
FindFirstChernickCarmichaelNumber[3]
FindFirstChernickCarmichaelNumber[4]
FindFirstChernickCarmichaelNumber[5]
FindFirstChernickCarmichaelNumber[6]
FindFirstChernickCarmichaelNumber[7]
FindFirstChernickCarmichaelNumber[8]
FindFirstChernickCarmichaelNumber[9]
Output
The output for the examples above will be pairs of the form {m, value}
, where m
is the first m
value that produces a number with the specified number of prime factors, and value
is that number.
Source code in the wolfram programming language
ClearAll[PrimeFactorCounts, U]
PrimeFactorCounts[n_Integer] := Total[FactorInteger[n][[All, 2]]]
U[n_, m_] := (6 m + 1) (12 m + 1) Product[2^i 9 m + 1, {i, 1, n - 2}]
FindFirstChernickCarmichaelNumber[n_Integer?Positive] :=
Module[{step, i, m, formula, value},
step = Ceiling[2^(n - 4)];
If[n > 5, step *= 5];
i = step;
formula = U[n, m];
PrintTemporary[Dynamic[i]];
While[True,
value = formula /. m -> i;
If[PrimeFactorCounts[value] == n,
Break[];
];
i += step
];
{i, value}
]
FindFirstChernickCarmichaelNumber[3]
FindFirstChernickCarmichaelNumber[4]
FindFirstChernickCarmichaelNumber[5]
FindFirstChernickCarmichaelNumber[6]
FindFirstChernickCarmichaelNumber[7]
FindFirstChernickCarmichaelNumber[8]
FindFirstChernickCarmichaelNumber[9]
You may also check:How to resolve the algorithm Array concatenation step by step in the min programming language
You may also check:How to resolve the algorithm Circles of given radius through two points step by step in the Lua programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the R programming language
You may also check:How to resolve the algorithm Sailors, coconuts and a monkey problem step by step in the Racket programming language
You may also check:How to resolve the algorithm Thue-Morse step by step in the J programming language