Anonymous user
Multi-base primes: Difference between revisions
m
→{{header|Pascal}}: Forget to inc number in IncInBaseDigits and to reset all digits to 0 in CnvtoBASE
m (→Up to base 62) |
m (→{{header|Pascal}}: Forget to inc number in IncInBaseDigits and to reset all digits to 0 in CnvtoBASE) |
||
Line 644:
{$MODE DELPHI}
{$OPTIMIZATION ON,ALL}
{$ELSE}
{$APPTYPE CONSOLE}
Line 653 ⟶ 652:
CharOfBase= '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
MINBASE = 2;
MAXBASE = 62;//
MAXDIGITCOUNT = 5;//6;
type
tdigits = packed record
dgtDgts : array [0..13] of byte;
dgtMaxIdx,
Line 665 ⟶ 664:
var
BoolPrimes: array of boolean;
function BuildWheel(primeLimit:Int64):NativeUint;
Line 772 ⟶ 751:
end;
procedure
var
q,r: Uint64;
Line 780 ⟶ 759:
with dgt do
Begin
fillchar(dgtDgts,SizeOf(dgtDgts),#0);
dgtNum:= n;
repeat
r := n;
q := n div
r -= q*
n := q;
dgtDgts[i] := r;
Line 803 ⟶ 783:
end;
function
var
tmpDgt,i: NativeInt;
Line 812 ⟶ 792:
i:= dgtMaxIdx;
repeat
tmpDgt := dgtDgts[i];
result *= base;
Line 822 ⟶ 800:
end;
procedure
var
i,q,tmp :NativeInt;
Line 828 ⟶ 806:
with dgt do
Begin
tmp := dgtMaxIdx;
i := 0;
repeat
q := dgtDgts[i]+1;
q -= (-ORD(q >=
dgtDgts[i] := q;
inc(i);
Line 842 ⟶ 820:
dgtMaxIdx := i;
end;
i := tmp;
repeat
Line 850 ⟶ 827:
dec(i);
until i <0;
inc(dgtNum);
dgtMaxDgtVal := q;
end;
Line 860 ⟶ 838:
begin
result := 0;
//divisible by every base
IF Digits.dgtDgts[0] = 0 then
EXIT;
IF base < MINBASE then base := MINBASE;
// if (MAXBASE - Base) <= (max-result) then BREAK;
max := (max+Base-MAXBASE);
Line 871 ⟶ 850:
for base := base TO MAXBASE do
begin
pr :=
inc(result,Ord(boolprimes[pr]));
//no chance to reach max then exit
Line 917 ⟶ 896:
var
dgt:tDigits;
sl : string[
base,i: Int32;
Begin
result := 0;
sl := '';
with dgt do
begin
base:= dgtMaxDgtVal+1;
IF base < MINBASE then
base := MINBASE;
i := dgtMaxIdx;
while (i>=0)do
Line 935 ⟶ 916:
end;
For base := base to MAXBASE do
if boolprimes[
begin
inc(result);
Line 966 ⟶ 947:
T0 : Int64;
i : NativeInt;
lmt,minLmt :
begin
T0 := GetTickCount64;
Line 977 ⟶ 957:
Sieve(lmt);
writeln('Prime sieving ',(GetTickCount64-T0)/1000:6:3,' s');
T0 := GetTickCount64;
CnvtoBASE(dgt,0,MAXBASE);
i := 1;
minLmt := 1;
|