Jump to content

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;//8802377;// >750
type
EndDigittP4n3 := array[0..9] of Uint32;
 
function CommaUint(n : Uint64):AnsiString;
Line 454 ⟶ 456:
end;
 
procedure Sieve4n_3_Primes(Limit:Uint32;var P4n3:tP4n3);
var
BlumFieldsieve : array [0..LIMIT] of booleanbyte;
BlumPrimes BlPrCnt,idx,n,j: array[0..332398] of Uint32;
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
//sieve primes 4*i+3
n := (LIMIT DIV 3 -3) DIV 4+ 1;
setlength(sieve,n);
setlength(P4n3,n);
 
BlPrCnt:= 0;
IDXidx := 0;
repeat
if NOT(sieve[idx])= 0 then
begin
n := idx*4+3;
BlumPrimesP4n3[BlPrCnt] := n;
inc(BlPrCnt);
j := idx+n;
Line 476 ⟶ 479:
while j <= High(sieve) do
begin
sieve[j] := true1;
inc(j,n);
end;
Line 484 ⟶ 487:
//collect the rest
for idx := idx+1 to High(sieve) do
if NOT(sieve[idx])=0 then
Begin
BlumPrimesP4n3[BlPrCnt] := idx*4+3;
inc(BlPrCnt);
end;
writelnsetlength('There 'P4n3,BlPrCnt,' primes 4*n+3 to Limit ',LIMIT);
decsetlength(BlPrCntsieve,0);
end;
 
var
sieveBlumField : array[0..((LIMIT-3) DIV 4)] of boolean;
BlumPrimes : tP4n3;
EndDigit : array[0..9] of Uint32;
k : Uint64;
n,idx,j,k,BlPrCntP4n3Cnt : Uint64Uint32;
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 BlPrCntP4n3Cnt do
Begin
n := BlumPrimes[idx];
For j := idx+1 to BlPrCntP4n3Cnt do
Begin
k := n*BlumPrimes[j];
Line 509 ⟶ 526:
j := 0 ;
repeat
while (idx<LIMIT) AND Not(BlumField[idx]) do
inc(idx);
if EndDigit[j]idx <>= 0LIMIT then
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 ;
idxn := 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
writelnwrite(CommaUint(j):810,'.th Blum integer is:| ',CommaUint(idx):1011,'| ');
writelnwrite('Digit ',j:2,' rel. ',EndDigit[j1]/idxj*100:7:3,'% |');
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;
For j := 0 to 9 do
inc(idx,EndDigit[j]);
For j := 0 to 9 do
if EndDigit[j] <> 0 then
writeln('Digit ',j:2,' rel. ',EndDigit[j]/idx*100:7:3,'%');
end.</syntaxhighlight>
{{out|@TIO.RUN}}
<pre>
There 332398are 119,644 needed primes 4*n+3 to Limit 1000000010,000,000
 
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
26,828.th Blum integer is: 524,273
n.th |Blum-Integer| 1 3 7 9
100,000.th Blum integer is: 2,075,217
26,828 | 524,273| 24.933% | 25.071% | 25.030% | 24.966%
200,000.th Blum integer is: 4,275,533
100,000 | 2,075,217| 24.973% | 25.026% | 25.005% | 24.996%
300,000.th Blum integer is: 6,521,629
200,000 | 4,275,533| 24.990% | 24.986% | 25.033% | 24.992%
400,000.th Blum integer is: 8,802,377
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%
Digit 1 rel. 25.001%
Digit 3 rel. 25.017%
Digit 7 rel. 24.997%
Digit 9 rel. 24.985%
 
Real time: 0.108097 s User time: 0.076068 s Sys. time: 0.032028 s CPU share: 9899.9008 %
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>
132

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.