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

Content added Content deleted
Line 342: Line 342:


=={{header|EasyLang}}==
=={{header|EasyLang}}==
{{trans|C}}
{{trans|C}} (optimized)
<syntaxhighlight>
<syntaxhighlight>
fastfunc is_substring n k .
fastfunc isin n k .
pfx = k
h = k
while n > 0
while n > 0
if pfx mod 10 = n mod 10
if h mod 10 = n mod 10
pfx = pfx div 10
h = h div 10
if startMatch = 0
if match = 0
startMatch = n
match = n
.
.
else
else
pfx = k
h = k
if startMatch <> 0
if match <> 0
n = startMatch
n = match
.
.
startMatch = 0
match = 0
.
.
if pfx = 0
if h = 0
return 1
return 1
.
.
Line 366: Line 366:
return 0
return 0
.
.

fastfunc facts_are_subs n .
fastfunc test n .
if n mod 2 = 0 or n mod 3 = 0 or n mod 5 = 0 or n mod 7 = 0
if n mod 2 = 0 or n mod 3 = 0 or n mod 5 = 0 or n mod 7 = 0
return 0
return 0
.
.
factor_count = 0
rest = n
n_rest = n
fact = 11
factor = 11
while fact <= rest
if rest mod fact = 0
while factor <= n_rest
if n_rest mod factor = 0
while rest mod fact = 0
while n_rest mod factor = 0
rest /= fact
n_rest /= factor
.
.
if is_substring n factor = 0
if isin n fact = 0
return 0
return 0
.
.
factor_count += 1
nfacts += 1
.
.
factor += 2
fact += 2
if factor > sqrt n and factor_count = 0
if fact > sqrt n and nfacts = 0
return 0
return 0
.
.
.
.
if factor_count > 1
if nfacts > 1
return 1
return 1
.
.
Line 394: Line 394:
.
.
n = 11
n = 11
while amount < 10
while count < 10
if facts_are_subs n = 1
if test n = 1
print n
print n
amount += 1
count += 1
.
.
n += 2
n += 2