Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Goldbachs-comet/FreeBASIC/goldbachs-comet-1.basic
Normal file
29
Task/Goldbachs-comet/FreeBASIC/goldbachs-comet-1.basic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Function isPrime(Byval ValorEval As Uinteger) As Boolean
|
||||
If ValorEval <= 1 Then Return False
|
||||
For i As Integer = 2 To Int(Sqr(ValorEval))
|
||||
If ValorEval Mod i = 0 Then Return False
|
||||
Next i
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Function g(n As Uinteger) As Uinteger
|
||||
Dim As Uinteger i, count = 0
|
||||
If (n Mod 2 = 0) Then 'n in goldbach function g(n) must be even
|
||||
For i = 2 To (1/2) * n
|
||||
If isPrime(i) And isPrime(n - i) Then count += 1
|
||||
Next i
|
||||
End If
|
||||
Return count
|
||||
End Function
|
||||
|
||||
Print "The first 100 G numbers are:"
|
||||
|
||||
Dim As Uinteger col = 1
|
||||
For n As Uinteger = 4 To 202 Step 2
|
||||
Print Using "####"; g(n);
|
||||
If (col Mod 10 = 0) Then Print
|
||||
col += 1
|
||||
Next n
|
||||
|
||||
Print !"\nThe value of G(1000000) is "; g(1000000)
|
||||
Sleep
|
||||
47
Task/Goldbachs-comet/FreeBASIC/goldbachs-comet-2.basic
Normal file
47
Task/Goldbachs-comet/FreeBASIC/goldbachs-comet-2.basic
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
OPTION STRICT: OPTION DEFINT
|
||||
VAR MAX_G = 4000, MAX_P = 1000000
|
||||
VAR ROOT_MAX_P = FLOOR(SQR(MAX_P))
|
||||
VAR HALF_MAX_G = MAX_G DIV 2
|
||||
VAR G[MAX_G + 1], P[MAX_P + 1]
|
||||
VAR I, J
|
||||
CLS: GCLS
|
||||
P[0] = FALSE: P[1] = 0: P[2] = TRUE
|
||||
FOR I = 4 TO MAX_P STEP 2 P[I] = FALSE: NEXT
|
||||
FOR I = 3 TO MAX_P STEP 2 P[I] = TRUE: NEXT
|
||||
FOR I = 3 TO ROOT_MAX_P STEP 2
|
||||
IF P[I] THEN
|
||||
FOR J = I * I TO MAX_P STEP I
|
||||
P[J] = FALSE
|
||||
NEXT
|
||||
ENDIF
|
||||
NEXT
|
||||
FOR I = 1 TO MAX_G G[I] = 0: NEXT
|
||||
G[4] = 1 ' 4 is the only sum of 2 even primes
|
||||
FOR I = 3 TO HALF_MAX_G STEP 2
|
||||
IF P[I] THEN
|
||||
INC G[I + 1]
|
||||
FOR J = I + 2 TO MAX_G - 1
|
||||
IF P[J] THEN
|
||||
INC G[I + 1]
|
||||
ENDIF
|
||||
NEXT
|
||||
ENDIF
|
||||
NEXT
|
||||
VAR C = 0
|
||||
FOR I = 4 TO 202 STEP 2
|
||||
PRINT FORMAT$("%3D", G[I]),
|
||||
INC C
|
||||
IF C == 10 THEN PRINT: C = 0: ENDIF
|
||||
NEXT
|
||||
VAR GM = 0
|
||||
FOR I = 3 TO MAX_P DIV 2 STEP 2
|
||||
IF P[I] THEN
|
||||
IF P[MAX_P - I] THEN INC GM: ENDIF
|
||||
ENDIF
|
||||
NEXT
|
||||
PRINT FORMAT$("G(%D): ", MAX_P); GM
|
||||
FOR I = 2 TO MAX_G - 10 STEP 10
|
||||
FOR J = 1 TO I + 8 STEP 2
|
||||
GPSET I DIV 10, 240-G[J],RGB(255,255,255)
|
||||
NEXT
|
||||
NEXT
|
||||
Loading…
Add table
Add a link
Reference in a new issue