Anonymous user
Multi-base primes: Difference between revisions
m
→{{header|Pascal}}: check count of primes in base enpassant no need for big array BaseCnvCount (10 Mbyte for 6 digits )
m (→{{header|REXX}}: added the number of bases found for any maximums.) |
m (→{{header|Pascal}}: check count of primes in base enpassant no need for big array BaseCnvCount (10 Mbyte for 6 digits )) |
||
Line 455:
{$MODE DELPHI}
{$OPTIMIZATION ON,ALL}
{$ELSE}
{$APPTYPE CONSOLE}
Line 467:
MAXFAC = 10*10*10*10*10*10;//10*10*10*10*10*10*10*10*10;//
type
tdigits = array [0..15] of byte;//must be 0..15
tSol = array of Uint32;
//sieve primes see http://rosettacode.org/wiki/Sieve_of_Eratosthenes#alternative_using_wheel
var
BoolPrimes: array of boolean;
function BuildWheel(primeLimit:Int32):NativeUint;
Line 563 ⟶ 561:
function getDecDigitsAndMaxDgt(n:Uint32;var dgt:tDigits):uint32;
var
pQ :pQWord;
q,r,i: Uint32;
Begin
//aka fillChar(dgt[0],SizeOf(dgt),#0);
i := 0;
result := 0;
Line 594:
end;
var
Digits :tdigits;
base
begin
//base 10
//minimalBase <= max. digit +1
//this takes 0.012s out of 0.155s
if base
base := MinBase;
for base :=
inc(
for base := 11 TO MAXBASE do
inc(
end;
function
var
i,
Begin
setlength(result,0);
Line 623 ⟶ 622:
For i := MinLmt to MaxLmt do
Begin
if
continue;
if max<=
begin
if max =
begin
inc(Idx);
Line 639 ⟶ 638:
Idx:= 1;
setlength(result,1);
result[
max :=
end;
end;
Line 647 ⟶ 646:
function Out_String(n:Uint32;var s: AnsiString):Uint32;
//out-sourced for debugging purpose
var
dgt:tDigits;
Line 653:
Begin
result := 0;
minimalbase:= getDecDigitsAndMaxDgt(n,dgt)+1;▼
str(n:7,sl);
s := sl+' -> [';
▲ minimalbase:= getDecDigitsAndMaxDgt(n,dgt)+1;
For base := minimalbase to MAXBASE do
if boolprimes[CnvtoBase(dgt,base)] then
Line 695:
writeln('max prime limit ',lmt);
Sieve(lmt);
▲ write('Prime sieving ',(GetTickCount64-T0)/1000:6:3,' s');
T0 := GetTickCount64;
writeln(' Converting ',(GetTickCount64-T0)/1000:6:3,' s');▼
i := 1;
minLmt := 1;
repeat
write(i:2,' character strings which are prime in count bases = ');
Out_Sol(
minLmt *= 10;
inc(i);
until minLmt >= MAXFAC;
▲ writeln(' Converting ',(GetTickCount64-T0)/1000:6:3,' s');
{$IFDEF WINDOWS} readln; {$ENDIF}
end.</lang>
{{out}}
<pre>
TIO.RUN
max prime limit 559744029
Prime sieving 2.
1 character strings which are prime in count bases = 34
2 -> [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]
Line 741 ⟶ 734:
441431 -> [5,8,9,11,12,14,16,17,19,21,22,23,26,28,30,31,32,33]
Converting 0.333 s
//at home
//Prime sieving 1.
=={{header|Phix}}==
|