Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
89
Task/Blum-integer/Ada/blum-integer.ada
Normal file
89
Task/Blum-integer/Ada/blum-integer.ada
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
|
||||
procedure Blum is
|
||||
|
||||
Inc : Constant array (1 .. 8) of Integer := (4, 2, 4, 2, 4, 6, 2, 6);
|
||||
|
||||
function Is_Prime (N : Integer) return Boolean is
|
||||
D : Integer := 5;
|
||||
begin
|
||||
if N < 2 then return False; end if;
|
||||
if N mod 2 = 0 then return N = 2; end if;
|
||||
if N mod 3 = 0 then return N = 3; end if;
|
||||
|
||||
while D * D <= N loop
|
||||
if N mod D = 0 then return False; end if;
|
||||
D := D + 2;
|
||||
if N mod D = 0 then return False; end if;
|
||||
D := D + 4;
|
||||
end loop;
|
||||
|
||||
return True;
|
||||
end Is_Prime;
|
||||
|
||||
function First_Prime_Factor (N : Integer) return Integer is
|
||||
D : Integer := 7;
|
||||
I : Integer := 1;
|
||||
begin
|
||||
if N = 1 then return 1; end if;
|
||||
if N mod 3 = 0 then return 3; end if;
|
||||
if N mod 5 = 0 then return 5; end if;
|
||||
|
||||
while D * D <= N loop
|
||||
if N mod D = 0 then
|
||||
return D;
|
||||
end if;
|
||||
D := D + Inc(I);
|
||||
I := (I mod 8) + 1;
|
||||
end loop;
|
||||
|
||||
return N;
|
||||
end First_Prime_Factor;
|
||||
|
||||
I, Blum_Count : Integer := 1;
|
||||
J, P, Q : Integer;
|
||||
Blums : Array (1 .. 50) of Integer;
|
||||
Counts : Array (1 .. 4) of Integer := (others => 0);
|
||||
Final_Digits : Array (1 .. 4) of Integer := (1, 3, 7, 9);
|
||||
|
||||
begin
|
||||
loop
|
||||
P := First_Prime_Factor(I);
|
||||
if P mod 4 = 3 then
|
||||
Q := I / P;
|
||||
if Q /= P and Q mod 4 = 3 and Is_Prime(Q) then
|
||||
if Blum_Count < 51 then Blums(Blum_Count) := I; end if;
|
||||
Counts(((I mod 10) / 3) + 1) := Counts(((I mod 10) / 3) + 1) + 1;
|
||||
Blum_Count := Blum_Count + 1;
|
||||
if Blum_Count = 51 then
|
||||
Put("First 50 Blum Integers:"); New_Line;
|
||||
for J in Integer range 1 .. 50 loop
|
||||
Put(Item => Blums(J), Width => 3); Put(" ");
|
||||
if J mod 10 = 0 then New_Line; end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
elsif Blum_Count = 26829 or Blum_Count mod 100000 = 1 then
|
||||
Put("The "); Put(Item => Blum_Count, Width => 7);
|
||||
Put("th Blum Integer is: "); Put(Item => I, Width => 9);
|
||||
New_Line;
|
||||
if Blum_Count = 400001 then
|
||||
New_Line; Put("% Distribution of the First 400,000 Blum Integers:"); New_Line;
|
||||
for J in Integer range 1 .. 4 loop
|
||||
Put(" "); Put(Item => Float(Counts(J)) / 4000.0, Fore => 2, Aft => 3, Exp => 0);
|
||||
Put("% end in "); Put(Item => Final_Digits(J), Width => 1);
|
||||
New_Line;
|
||||
end loop;
|
||||
exit;
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
if I mod 5 = 3 then
|
||||
I := I + 4;
|
||||
else
|
||||
I := I + 2;
|
||||
end if;
|
||||
end loop;
|
||||
end Blum;
|
||||
158
Task/Blum-integer/Fortran/blum-integer.f
Normal file
158
Task/Blum-integer/Fortran/blum-integer.f
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
program BlumInteger
|
||||
use, intrinsic :: iso_fortran_env, only: int32, int64
|
||||
implicit none
|
||||
|
||||
integer(int32), parameter :: LIMIT = 10*1000*1000
|
||||
integer(int32), allocatable :: BlumPrimes(:)
|
||||
integer(int32), allocatable :: BlumPrimes2(:)
|
||||
logical :: BlumField(0:LIMIT)
|
||||
integer(int32) :: EndDigit(0:9)
|
||||
integer(int64) :: k
|
||||
integer(int32) :: n, idx, j, P4n3Cnt,xx,yy
|
||||
call system_clock(count=xx)
|
||||
call Sieve4n_3_Primes(LIMIT, BlumPrimes2)
|
||||
! allocate(blumprimes(0:size(BlumPrimes2)-1))
|
||||
! The blumprimes2 array is allocated in the subroutine as a zero based array
|
||||
! but, the main program doesn't know that and assumes it's 1 based so we allocate
|
||||
! a zero based array then use move_alloc to correctly resize it a transfer the data
|
||||
allocate(blumprimes(0:1))
|
||||
call move_alloc(blumprimes2,blumprimes)
|
||||
P4n3Cnt = size(BlumPrimes) -1
|
||||
print *, 'There are ', CommaUint(int(P4n3Cnt, int64)), ' needed primes 4*n+3 to Limit ', CommaUint(int(LIMIT, int64))
|
||||
P4n3Cnt = P4n3Cnt - 1
|
||||
print *
|
||||
|
||||
! Generate Blum-Integers
|
||||
BlumField = .false.
|
||||
do idx = 0, P4n3Cnt
|
||||
n = BlumPrimes(idx)
|
||||
do j = idx+1, P4n3Cnt
|
||||
k = int(n, int64) * int(BlumPrimes(j), int64)
|
||||
if (k > LIMIT) exit
|
||||
BlumField(k) = .true.
|
||||
end do
|
||||
end do
|
||||
call system_clock(count=yy)
|
||||
print *, 'First 50 Blum-Integers '
|
||||
idx = 0
|
||||
j = 0
|
||||
do
|
||||
do while (idx < LIMIT .and. .not. BlumField(idx))
|
||||
idx = idx + 1
|
||||
end do
|
||||
if (idx == LIMIT) exit
|
||||
if (mod(j, 10) == 0 .and. j /= 0) print *
|
||||
write(*, '(I5)', advance='no') idx
|
||||
j = j + 1
|
||||
idx = idx + 1
|
||||
if (j >= 50) exit
|
||||
end do
|
||||
print '(//)'
|
||||
|
||||
print *, ' relative occurence of digit'
|
||||
print *, ' n.th |BlumInteger|Digit: 1 3 7 9'
|
||||
idx = 0
|
||||
j = 0
|
||||
n = 0
|
||||
k = 26828
|
||||
EndDigit = 0
|
||||
do
|
||||
do while (idx < LIMIT .and. .not. BlumField(idx))
|
||||
idx = idx + 1
|
||||
end do
|
||||
if (idx == LIMIT) exit
|
||||
! Count last decimal digit
|
||||
EndDigit(mod(idx, 10)) = EndDigit(mod(idx, 10)) + 1
|
||||
j = j + 1
|
||||
if (j == k) then
|
||||
write(*, '(A10,A1,A11,A1)', advance='no') CommaUint(int(j, int64)), '|', CommaUint(int(idx, int64)), '|'
|
||||
write(*, '(F7.3,A4)', advance='no') real(EndDigit(1))/j*100, '% |'
|
||||
write(*, '(F7.3,A4)', advance='no') real(EndDigit(3))/j*100, '% |'
|
||||
write(*, '(F7.3,A4)', advance='no') real(EndDigit(7))/j*100, '% |'
|
||||
write(*, '(F7.3,A2)') real(EndDigit(9))/j*100, '%'
|
||||
if (k < 100000) then
|
||||
k = 100000
|
||||
else
|
||||
k = k + 100000
|
||||
end if
|
||||
end if
|
||||
idx = idx + 1
|
||||
if (j >= 400000) exit
|
||||
end do
|
||||
print '(/,a,f8.6,1x,a)', 'Elapsed time = ',(yy-xx)/1000.0,'seconds'
|
||||
contains
|
||||
|
||||
subroutine Sieve4n_3_Primes(Limit, P4n3)
|
||||
use iso_fortran_env
|
||||
integer(int32), intent(in) :: Limit
|
||||
integer(int32), allocatable, intent(out) :: P4n3(:)
|
||||
integer(kind=1), allocatable :: sieve(:)
|
||||
integer(int32) :: BlPrCnt, idx, n, j, sieve_size
|
||||
|
||||
sieve_size = (Limit / 3 - 3) / 4 + 1
|
||||
allocate(sieve(0:sieve_size-1))
|
||||
allocate(P4n3(0:sieve_size-1))
|
||||
|
||||
sieve = 0
|
||||
BlPrCnt = 0
|
||||
idx = 0
|
||||
do
|
||||
if (sieve(idx) == 0) then
|
||||
n = idx*4 + 3
|
||||
P4n3(BlPrCnt) = n
|
||||
BlPrCnt = BlPrCnt + 1
|
||||
j = idx + n
|
||||
if (j > ubound(sieve, 1)) exit
|
||||
do while (j <= ubound(sieve, 1))
|
||||
sieve(j) = 1
|
||||
j = j + n
|
||||
end do
|
||||
end if
|
||||
idx = idx + 1
|
||||
if (idx > ubound(sieve, 1)) exit
|
||||
end do
|
||||
! Collect the rest
|
||||
do idx = idx, ubound(sieve, 1)
|
||||
if (sieve(idx) == 0) then
|
||||
P4n3(BlPrCnt) = idx*4 + 3
|
||||
BlPrCnt = BlPrCnt + 1
|
||||
end if
|
||||
end do
|
||||
P4n3 = P4n3(0:BlPrCnt-1)
|
||||
end subroutine Sieve4n_3_Primes
|
||||
|
||||
function CommaUint(n) result(res)
|
||||
integer, parameter :: sizer = 30
|
||||
integer(int64), intent(in) :: n
|
||||
character(:), allocatable :: res
|
||||
character(len=sizer) :: temp
|
||||
integer :: fromIdx, toIdx, i
|
||||
character :: pRes(sizer)
|
||||
|
||||
write(temp, '(I0)') n
|
||||
fromIdx = len_trim(temp)
|
||||
toIdx = fromIdx - 1
|
||||
if (toIdx < 3) then
|
||||
res = temp(1:fromIdx)
|
||||
return
|
||||
end if
|
||||
allocate(res, mold=repeat(' ',sizer))
|
||||
toIdx = 4*(toIdx / 3) + mod(toIdx, 3) + 1
|
||||
pRes = ' '
|
||||
|
||||
do i = 1, fromIdx
|
||||
pRes(toIdx) = temp(fromIdx-i+1:fromIdx-i+1)
|
||||
toIdx = toIdx - 1
|
||||
if (mod(i, 3) == 0 .and. i /= fromIdx) then
|
||||
pRes(toIdx) = ','
|
||||
toIdx = toIdx - 1
|
||||
end if
|
||||
end do
|
||||
do i = 1,sizer ! Go from character array to string
|
||||
res(I:I) = pRes(i)
|
||||
end do
|
||||
!
|
||||
res = trim(adjustl(Res))
|
||||
end function CommaUint
|
||||
|
||||
end program BlumInteger
|
||||
|
|
@ -1,39 +1,76 @@
|
|||
Dim Shared As Uinteger Prime1
|
||||
Dim As Uinteger n = 3, c = 0, Prime2
|
||||
#include "isprime.bas"
|
||||
|
||||
Function isSemiprime(n As Uinteger) As Boolean
|
||||
Dim As Uinteger d = 3, c = 0
|
||||
While d*d <= n
|
||||
While n Mod d = 0
|
||||
If c = 2 Then Return False
|
||||
n /= d
|
||||
c += 1
|
||||
Wend
|
||||
d += 2
|
||||
Wend
|
||||
Prime1 = n
|
||||
Return c = 1
|
||||
Type PrimeHelper
|
||||
inc(7) As Integer
|
||||
idx As Integer
|
||||
End Type
|
||||
|
||||
Function initPrimeHelper() As PrimeHelper
|
||||
Dim helper As PrimeHelper
|
||||
helper.inc(0) = 4 : helper.inc(1) = 2 : helper.inc(2) = 4
|
||||
helper.inc(3) = 2 : helper.inc(4) = 4 : helper.inc(5) = 6
|
||||
helper.inc(6) = 2 : helper.inc(7) = 6
|
||||
helper.idx = 0
|
||||
Return helper
|
||||
End Function
|
||||
|
||||
Print "The first 50 Blum integers:"
|
||||
Do
|
||||
If isSemiprime(n) Then
|
||||
If Prime1 Mod 4 = 3 Then
|
||||
Prime2 = n / Prime1
|
||||
If (Prime2 <> Prime1) And (Prime2 Mod 4 = 3) Then
|
||||
c += 1
|
||||
If c <= 50 Then
|
||||
Print Using "####"; n;
|
||||
If c Mod 10 = 0 Then Print
|
||||
End If
|
||||
If c >= 26828 Then
|
||||
Print !"\nThe 26828th Blum integer is: " ; n
|
||||
Exit Do
|
||||
Function firstPrimeFactor(n As Integer) As Integer
|
||||
If n = 1 Then Return 1
|
||||
If n Mod 3 = 0 Then Return 3
|
||||
If n Mod 5 = 0 Then Return 5
|
||||
|
||||
Dim helper As PrimeHelper = initPrimeHelper()
|
||||
Dim k As Integer = 7
|
||||
|
||||
While k * k <= n
|
||||
If n Mod k = 0 Then Return k
|
||||
k += helper.inc(helper.idx)
|
||||
helper.idx = (helper.idx + 1) Mod 8
|
||||
Wend
|
||||
|
||||
Return n
|
||||
End Function
|
||||
|
||||
Sub main()
|
||||
Dim As Integer blum(49), counts(9)
|
||||
Dim As Integer bc = 0, i = 1, p, q
|
||||
Dim As Integer j
|
||||
|
||||
Dim As Double t0 = Timer
|
||||
Do
|
||||
p = firstPrimeFactor(i)
|
||||
If p Mod 4 = 3 Then
|
||||
q = i \ p
|
||||
If q <> p Andalso q Mod 4 = 3 Andalso isPrime(q) Then
|
||||
If bc < 50 Then blum(bc) = i
|
||||
counts(i Mod 10) += 1
|
||||
bc += 1
|
||||
|
||||
If bc = 50 Then
|
||||
Print "First 50 Blum integers:"
|
||||
For j = 0 To 49
|
||||
Print Using "####"; blum(j);
|
||||
If (j + 1) Mod 10 = 0 Then Print
|
||||
Next
|
||||
Print
|
||||
Elseif bc = 26828 Orelse bc Mod 100000 = 0 Then
|
||||
Print Using "The ###,###th Blum integer is: #,###,###"; bc; i
|
||||
|
||||
If bc = 400000 Then
|
||||
Print !"\n% distribution of the first 400,000 Blum integers:"
|
||||
For j = 1 To 9 Step 2
|
||||
If j <> 5 Then Print Using " ##.###% end in #"; (counts(j)/4000); j
|
||||
Next
|
||||
Exit Do
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
n += 2
|
||||
Loop
|
||||
i += Iif(i Mod 5 = 3, 4, 2)
|
||||
Loop
|
||||
Print Chr(10); Timer - t0; " sec."
|
||||
End Sub
|
||||
|
||||
main()
|
||||
|
||||
Sleep
|
||||
|
|
|
|||
|
|
@ -1,44 +1,67 @@
|
|||
Public Prime1 As Integer
|
||||
Use "isprime.bas"
|
||||
|
||||
Public Sub Main()
|
||||
Private inc As Integer[] = [4, 2, 4, 2, 4, 6, 2, 6]
|
||||
|
||||
Dim n As Integer = 3, c As Integer = 0, Prime2 As Integer
|
||||
Private Function FirstPrimeFactor(n As Long) As Long
|
||||
|
||||
Print "The first 50 Blum integers:"
|
||||
Do
|
||||
If isSemiprime(n) Then
|
||||
If Prime1 Mod 4 = 3 Then
|
||||
Prime2 = n / Prime1
|
||||
If (Prime2 <> Prime1) And (Prime2 Mod 4 = 3) Then
|
||||
c += 1
|
||||
If c <= 50 Then
|
||||
Print Format$(n, "####");
|
||||
If c Mod 10 = 0 Then Print
|
||||
End If
|
||||
If c >= 26828 Then
|
||||
Print "\nThe 26828th Blum integer is: "; n
|
||||
Break
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
n += 2
|
||||
Loop
|
||||
If n = 1 Then Return 1
|
||||
If n Mod 3 = 0 Then Return 3
|
||||
If n Mod 5 = 0 Then Return 5
|
||||
|
||||
Dim k As Long = 7
|
||||
Dim i As Integer = 0
|
||||
|
||||
While k * k <= n
|
||||
If n Mod k = 0 Then Return k
|
||||
k += inc[i]
|
||||
i = (i + 1) Mod 8
|
||||
Wend
|
||||
|
||||
Return n
|
||||
|
||||
End
|
||||
|
||||
Function isSemiprime(n As Integer) As Boolean
|
||||
Public Sub Main()
|
||||
|
||||
Dim d As Integer = 3, c As Integer = 0
|
||||
While d * d <= n
|
||||
While n Mod d = 0
|
||||
If c = 2 Then Return False
|
||||
n /= d
|
||||
c += 1
|
||||
Wend
|
||||
d += 2
|
||||
Dim blum As New Long[50]
|
||||
Dim counts As New Collection
|
||||
|
||||
counts[1] = 0
|
||||
counts[3] = 0
|
||||
counts[7] = 0
|
||||
counts[9] = 0
|
||||
|
||||
Dim bc As Long = 0, i As Long = 1
|
||||
|
||||
While True
|
||||
Dim p As Long = FirstPrimeFactor(i)
|
||||
If p Mod 4 = 3 Then
|
||||
Dim q As Long = i \ p
|
||||
If q <> p And q Mod 4 = 3 And IsPrime(q) Then
|
||||
If bc < 50 Then blum[bc] = i
|
||||
counts[i Mod 10] += 1
|
||||
bc += 1
|
||||
|
||||
If bc = 50 Then
|
||||
Print "First 50 Blum integers:"
|
||||
For j As Integer = 0 To 49
|
||||
Print Format(blum[j], "####"); " ";
|
||||
If (j + 1) Mod 10 = 0 Then Print
|
||||
Next
|
||||
Print
|
||||
Else If bc = 26828 Or bc Mod 100000 = 0 Then
|
||||
Print "The "; Format(bc, " ###,###"); "th Blum integer is: "; Format(i, " #,###,###")
|
||||
If bc = 400000 Then
|
||||
Print Chr(10); "% distribution of the first 400,000 Blum integers:"
|
||||
For Each j As Integer In [1, 3, 7, 9]
|
||||
Print Format(counts[j] / 4000, " ##.###"); "% end in "; j
|
||||
Next
|
||||
Return
|
||||
Endif
|
||||
Endif
|
||||
Endif
|
||||
Endif
|
||||
i += If(i Mod 5 = 3, 4, 2)
|
||||
Wend
|
||||
Prime1 = n
|
||||
Return c = 1
|
||||
|
||||
End Function
|
||||
End
|
||||
|
|
|
|||
78
Task/Blum-integer/OxygenBasic/blum-integer.basic
Normal file
78
Task/Blum-integer/OxygenBasic/blum-integer.basic
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "isprime.bas"
|
||||
uses console
|
||||
|
||||
dim inc(7) as integer
|
||||
inc(0) = 4: inc(1) = 2: inc(2) = 4
|
||||
inc(3) = 2: inc(4) = 4: inc(5) = 6
|
||||
inc(6) = 2: inc(7) = 6
|
||||
|
||||
function firstPrimeFactor(n as long) as long
|
||||
if n = 1 then return 1
|
||||
if n mod 3 = 0 then return 3
|
||||
if n mod 5 = 0 then return 5
|
||||
|
||||
long k = 7
|
||||
int idx = 0
|
||||
|
||||
while k * k <= n
|
||||
if mod(n, k) = 0 then return k
|
||||
k += inc(idx)
|
||||
idx = mod((idx + 1), 8)
|
||||
wend
|
||||
return n
|
||||
end function
|
||||
|
||||
sub main()
|
||||
dim as long blum(49), counts(9)
|
||||
long bc = 0, i = 1, pct, p, q
|
||||
int j
|
||||
string s, t
|
||||
|
||||
do
|
||||
p = firstPrimeFactor(i)
|
||||
if p mod 4 = 3 then
|
||||
q = i \ p
|
||||
if q <> p and q mod 4 = 3 and isPrime(q) then
|
||||
if bc < 50 then blum(bc) = i
|
||||
counts(i mod 10) = counts(i mod 10) + 1
|
||||
bc += 1
|
||||
|
||||
if bc = 50 then
|
||||
printl "First 50 Blum integers:"
|
||||
for j = 0 to 49
|
||||
s = str(blum(j))
|
||||
while len(s) < 4: s = " " + s: wend
|
||||
print s;
|
||||
if mod((j + 1), 10) = 0 then printl
|
||||
next
|
||||
printl
|
||||
elseif bc = 26828 or bc mod 100000 = 0 then
|
||||
s = str(bc)
|
||||
while len(s) < 6: s = " " + s: wend
|
||||
t = str(i)
|
||||
while len(t) < 7: t = " " + t: wend
|
||||
printl "The " + s + "th Blum integer is: " + t
|
||||
if bc = 400000 then
|
||||
printl cr "% distribution of the first 400,000 Blum integers:"
|
||||
|
||||
for j = 1 to 9 step 2
|
||||
if j <> 5 then
|
||||
pct = counts(j)/4000
|
||||
s = str(pct)
|
||||
while len(s) < 5: s = " " + s: wend
|
||||
printl s + "% end in " + str(j)
|
||||
end if
|
||||
next
|
||||
end
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
if mod(i, 5) = 3 then i += 4 else i += 2
|
||||
end do
|
||||
end sub
|
||||
|
||||
main()
|
||||
|
||||
printl cr "Enter ..."
|
||||
waitkey
|
||||
69
Task/Blum-integer/PureBasic/blum-integer.basic
Normal file
69
Task/Blum-integer/PureBasic/blum-integer.basic
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
XIncludeFile "isprime.pb"
|
||||
|
||||
Structure PrimeHelper
|
||||
inc.i[8]
|
||||
index.i
|
||||
EndStructure
|
||||
|
||||
Procedure.i firstPrimeFactor(n.q)
|
||||
If n = 1 : ProcedureReturn 1 : EndIf
|
||||
If n % 3 = 0 : ProcedureReturn 3 : EndIf
|
||||
If n % 5 = 0 : ProcedureReturn 5 : EndIf
|
||||
|
||||
Define helper.PrimeHelper
|
||||
helper\inc[0] = 4 : helper\inc[1] = 2 : helper\inc[2] = 4
|
||||
helper\inc[3] = 2 : helper\inc[4] = 4 : helper\inc[5] = 6
|
||||
helper\inc[6] = 2 : helper\inc[7] = 6
|
||||
|
||||
Define k.q = 7
|
||||
While k * k <= n
|
||||
If n % k = 0 : ProcedureReturn k : EndIf
|
||||
k + helper\inc[helper\index]
|
||||
helper\index = (helper\index + 1) % 8
|
||||
Wend
|
||||
ProcedureReturn n
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
Define Dim blum.q(49)
|
||||
Define.q bc = 0, i = 1
|
||||
Define Dim counts.q(9)
|
||||
|
||||
Repeat
|
||||
Define p.q = firstPrimeFactor(i)
|
||||
If p % 4 = 3
|
||||
Define q.q = i / p
|
||||
If q <> p And q % 4 = 3 And isPrime(q)
|
||||
If bc < 50 : blum(bc) = i : EndIf
|
||||
counts(i % 10) + 1
|
||||
bc + 1
|
||||
|
||||
If bc = 50
|
||||
PrintN("First 50 Blum integers:")
|
||||
For j = 0 To 49
|
||||
Print(" " + RSet(Str(blum(j)), 3))
|
||||
If (j + 1) % 10 = 0 : PrintN("") : EndIf
|
||||
Next
|
||||
PrintN("")
|
||||
ElseIf bc = 26828 Or bc % 100000 = 0
|
||||
PrintN("The " + RSet(Str(bc), 6) + "th Blum integer is: " + RSet(Str(i), 7))
|
||||
If bc = 400000
|
||||
PrintN(#CRLF$ + "% distribution of the first 400,000 Blum integers:")
|
||||
For j = 1 To 9 Step 2
|
||||
If j <> 5
|
||||
PrintN(RSet(StrF(counts(j)/4000, 3), 5) + "% end in " + Str(j))
|
||||
EndIf
|
||||
Next
|
||||
Break
|
||||
EndIf
|
||||
EndIf
|
||||
EndIf
|
||||
EndIf
|
||||
If i % 5 = 3
|
||||
i + 4
|
||||
Else
|
||||
i + 2
|
||||
EndIf
|
||||
ForEver
|
||||
|
||||
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
|
||||
73
Task/Blum-integer/QB64/blum-integer.qb64
Normal file
73
Task/Blum-integer/QB64/blum-integer.qb64
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
Dim Shared inc(7) As Integer
|
||||
inc(0) = 4: inc(1) = 2: inc(2) = 4
|
||||
inc(3) = 2: inc(4) = 4: inc(5) = 6
|
||||
inc(6) = 2: inc(7) = 6
|
||||
|
||||
Dim blum(49) As Long
|
||||
Dim counts(9) As Long
|
||||
Dim bc As Long, i As Long, p As Long, q As Long, j As Integer
|
||||
i = 1
|
||||
|
||||
Do
|
||||
p = firstPrimeFactor(i)
|
||||
If p Mod 4 = 3 Then
|
||||
q = i \ p
|
||||
If q <> p And q Mod 4 = 3 And isPrime(q) Then
|
||||
If bc < 50 Then blum(bc) = i
|
||||
counts(i Mod 10) = counts(i Mod 10) + 1
|
||||
bc = bc + 1
|
||||
|
||||
If bc = 50 Then
|
||||
Print "First 50 Blum integers:"
|
||||
For j = 0 To 49
|
||||
Print Using "####"; blum(j);
|
||||
If (j + 1) Mod 10 = 0 Then Print
|
||||
Next
|
||||
Print
|
||||
ElseIf bc = 26828 Or bc Mod 100000 = 0 Then
|
||||
Print Using "The ###,###th Blum integer is: #,###,###"; bc; i
|
||||
If bc = 400000 Then
|
||||
Print Chr$(10); "% distribution of the first 400,000 Blum integers:"
|
||||
For j = 1 To 9 Step 2
|
||||
If j <> 5 Then
|
||||
Print Using " ##.###% end in #"; (counts(j%) / 4000); j%
|
||||
End If
|
||||
Next
|
||||
End
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
If i Mod 5 = 3 Then i = i + 4 Else i = i + 2
|
||||
Loop
|
||||
End
|
||||
|
||||
Function firstPrimeFactor& (n As Long)
|
||||
Dim k As Long, idx As Integer
|
||||
If n = 1 Then firstPrimeFactor& = 1: Exit Function
|
||||
If n Mod 3 = 0 Then firstPrimeFactor& = 3: Exit Function
|
||||
If n Mod 5 = 0 Then firstPrimeFactor& = 5: Exit Function
|
||||
k = 7: idx = 0
|
||||
Do While k * k <= n
|
||||
If n Mod k = 0 Then
|
||||
firstPrimeFactor& = k
|
||||
Exit Function
|
||||
End If
|
||||
k = k + inc(idx)
|
||||
idx = (idx + 1) Mod 8
|
||||
Loop
|
||||
firstPrimeFactor& = n
|
||||
End Function
|
||||
|
||||
Function isPrime% (n As Long)
|
||||
Dim i As Long
|
||||
If n <= 1 Then Exit Function
|
||||
If n <= 3 Then isPrime% = 1: Exit Function
|
||||
If n Mod 2 = 0 Or n Mod 3 = 0 Then Exit Function
|
||||
i = 5
|
||||
While i * i <= n
|
||||
If n Mod i = 0 Or n Mod (i + 2) = 0 Then Exit Function
|
||||
i = i + 6
|
||||
Wend
|
||||
isPrime% = 1
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue