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

no edit summary
No edit summary
Line 109:
2237411
3129361</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
 
procedure MultidigitComposites(Memo: TMemo);
var I,Cnt: integer;
var IA: TIntegerDynArray;
var Sieve: TPrimeSieve;
 
 
function MatchCriteria(N: integer): boolean;
{Test N against Criteria}
var I,L: integer;
var SN,ST: string;
begin
Result:=False;
{No even numbers}
if (N and 1)=0 then exit;
{N can't be prime}
if Sieve[N] then exit;
I:=3;
SN:=IntToStr(N);
repeat
begin
{Is it a factor }
if (N mod I) = 0 then
begin
{No one-digit numbers}
if I<10 then exit;
{Factor string must be found in N's string}
ST:=IntToStr(I);
if Pos(ST,SN)<1 then exit;
N:=N div I;
end
else I:=I+2;
end
until N<=1;
Result:=True;
end;
 
 
begin
Sieve:=TPrimeSieve.Create;
try
{Create 30 million primes}
Sieve.Intialize(30000000);
Cnt:=0;
{Smallest prime factor}
I:=11*11;
while I<High(integer) do
begin
{Test if I matches criteria}
if MatchCriteria(I) then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+' - '+FloatToStrF(I,ffNumber,18,0));
if Cnt>=20 then break;
end;
Inc(I,2);
end;
finally Sieve.Free; end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 - 15,317
2 - 59,177
3 - 83,731
4 - 119,911
5 - 183,347
6 - 192,413
7 - 1,819,231
8 - 2,111,317
9 - 2,237,411
10 - 3,129,361
11 - 5,526,173
12 - 11,610,313
13 - 13,436,683
14 - 13,731,373
15 - 13,737,841
16 - 13,831,103
17 - 15,813,251
18 - 17,692,313
19 - 19,173,071
20 - 28,118,827
Elapsed Time: 02:39.291 min
</pre>
 
 
=={{header|F_Sharp|F#}}==
465

edits