Composite numbers k with no single digit factors whose factors are all substrings of k: Difference between revisions

Added XPL0 example.
m (→‎{{header|Free Pascal}}: added Numb2USA aka commatize)
(Added XPL0 example.)
Line 787:
15,317 59,177 83,731 119,911 183,347 192,413 1,819,231 2,111,317 2,237,411 3,129,361
5,526,173 11,610,313 13,436,683 13,731,373 13,737,841 13,831,103 15,813,251 17,692,313 19,173,071 28,118,827
</pre>
 
=={{header|XPL0}}==
Runs in 33.6 seconds on Raspberry Pi 4.
<lang XPL0>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;
]</lang>
 
{{out}}
<pre>
15,317 59,177 83,731 119,911 183,347 192,413 1,819,231 2,111,317 2,237,411 3,129,361
5,526,173 11,610,313 13,436,683 13,731,373 13,737,841 13,831,103 15,813,251 17,692,313 19,173,071 28,118,827
</pre>
772

edits