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

Content added Content deleted
(Created Nim solution.)
(Set the number of results to 20 as required.)
Line 353: Line 353:
We use a sieve to build a list of prime factors. This is more efficient than computing the list of prime factors on the fly.
We use a sieve to build a list of prime factors. This is more efficient than computing the list of prime factors on the fly.


To find the 25 first elements of the sequence, the program takes about 23 seconds on an Intel Core I5-8250U 4×1.6GHz.
To find the 20 first elements of the sequence, the program takes less than 10 seconds on an Intel Core I5-8250U 4×1.6GHz.
<syntaxhighlight lang="Nim">import std/[strformat, strutils]
<syntaxhighlight lang="Nim">import std/[strformat, strutils]


Line 372: Line 372:
primeFactors(k).add n
primeFactors(k).add n


const N = 25 # Number of results.
const N = 20 # Number of results.
var n = 11 * 11
var n = 11 * 11
var count = 0
var count = 0
Line 407: Line 407:
19: 19_173_071
19: 19_173_071
20: 28_118_827
20: 28_118_827
21: 31_373_137
22: 47_458_321
23: 55_251_877
24: 62_499_251
25: 79_710_361
</pre>
</pre>