Blum integer: Difference between revisions
m
→{{header|Free Pascal}}: changed output format
(Replace the "blum" sequence with an array.) |
m (→{{header|Free Pascal}}: changed output format) |
||
Line 420:
}
const
LIMIT = 10*1000*1000;//
type
function CommaUint(n : Uint64):AnsiString;
Line 454 ⟶ 456:
end;
procedure Sieve4n_3_Primes(Limit:Uint32;var P4n3:tP4n3);
var
sieve : array[0..((LIMIT-3) DIV 4)] of boolean;▼
▲ EndDigit : array[0..9] of Uint32;
n,idx,j,k,BlPrCnt : Uint64;▼
begin
//DIV 3 -> smallest factor of Blum Integer
n := (LIMIT DIV 3 -3) DIV 4+ 1;
setlength(sieve,n);
setlength(P4n3,n);
BlPrCnt:= 0;
repeat
if
begin
n := idx*4+3;
inc(BlPrCnt);
j := idx+n;
Line 476 ⟶ 479:
while j <= High(sieve) do
begin
sieve[j] :=
inc(j,n);
end;
Line 484 ⟶ 487:
//collect the rest
for idx := idx+1 to High(sieve) do
if
Begin
inc(BlPrCnt);
end;
end;
var
BlumPrimes : tP4n3;
EndDigit : array[0..9] of Uint32;
k : Uint64;
begin
Sieve4n_3_Primes(Limit,BlumPrimes);
P4n3Cnt := length(BlumPrimes);
writeln('There are ',CommaUint(P4n3Cnt),' needed primes 4*n+3 to Limit ',CommaUint(LIMIT));
dec(P4n3Cnt);
writeln;
//generate Blum-Integers
For idx := 0 to
Begin
n := BlumPrimes[idx];
For j := idx+1 to
Begin
k := n*BlumPrimes[j];
Line 509 ⟶ 526:
j := 0 ;
repeat
while (idx<LIMIT) AND Not(BlumField[idx]) do
inc(idx);
BREAK;
if j mod 10 = 0 then
writeln;
Line 520 ⟶ 539:
//count and calc and summate decimal digit
writeln(' relative occurence of digit');
writeln(' n.th |Blum-Integer|Digit: 1 3 7 9');
idx :=0;
j := 0 ;
k := 26828;
repeat
while (idx<LIMIT) AND Not(BlumField[idx]) do
inc(idx);
if idx = LIMIT then
BREAK;
//count last decimal digit
inc(EndDigit[idx MOD 10]);
Line 531 ⟶ 555:
if j = k then
begin
write(EndDigit[3]/j*100:7:3,'% |');
write(EndDigit[7]/j*100:7:3,'% |');
writeln(EndDigit[9]/j*100:7:3,'%');
if k < 100000 then
k := 100000
Line 540 ⟶ 568:
until j >= 400000;
Writeln;
▲ idx := 0;
▲ if EndDigit[j] <> 0 then
▲ writeln('Digit ',j:2,' rel. ',EndDigit[j]/idx*100:7:3,'%');
end.</syntaxhighlight>
{{out|@TIO.RUN}}
<pre>
There
First 50 Blum-Integers
21 33 57 69 77 93 129 133 141 161
Line 559 ⟶ 581:
597 633 649 669 681 713 717 721 737 749
relative occurence of digit
n.th |Blum-Integer| 1 3 7 9
26,828 | 524,273| 24.933% | 25.071% | 25.030% | 24.966%
100,000 | 2,075,217| 24.973% | 25.026% | 25.005% | 24.996%
200,000 | 4,275,533| 24.990% | 24.986% | 25.033% | 24.992%
300,000 | 6,521,629| 24.982% | 25.014% | 25.033% | 24.970%
400,000 | 8,802,377| 25.001% | 25.017% | 24.997% | 24.985%
Real time: 0.
C-Version //-O3 -marchive=native
Real time: 1.658 s User time: 1.612 s Sys. time: 0.033 s CPU share: 99.18 %</pre>
|