How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the XPL0 programming language
Table of Contents
Problem Statement
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the XPL0 programming language
Source code in the xpl0 programming language
include xpllib; \for ItoA, StrFind and RlOutC
int K, C;
proc Factor; \Show certain K factors
int L, N, F, Q;
char SA(10), SB(10);
[ItoA(K, SB);
L:= sqrt(K); \limit for speed
N:= K; F:= 3;
if (N&1) = 0 then return; \reject if 2 is a factor
loop [Q:= N/F;
if rem(0) = 0 then \found a factor, F
[if F < 10 then return; \reject if too small (3, 5, 7)
ItoA(F, SA); \reject if not a sub-string
if StrFind(SB, SA) = 0 then return;
N:= Q;
if F>N then quit; \all factors found
]
else [F:= F+2; \try next prime factor
if F>L then
[if N=K then return; \reject prime K
ItoA(N, SA); \ (it's not composite)
if StrFind(SB, SA) = 0 then return;
quit; \passed all restrictions
];
];
];
Format(9, 0);
RlOutC(0, float(K));
C:= C+1;
if rem(C/10) = 0 then CrLf(0);
];
[C:= 0; \initialize element counter
K:= 11*11; \must have at least two 2-digit composites
repeat Factor;
K:= K+2; \must be odd because all factors > 2 are odd primes
until C >= 20;
]
You may also check:How to resolve the algorithm Anagrams/Deranged anagrams step by step in the Groovy programming language
You may also check:How to resolve the algorithm Date format step by step in the Pascal programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Yorick programming language
You may also check:How to resolve the algorithm Inverted index step by step in the Rust programming language
You may also check:How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Raku programming language