

 This page uses content from Wikipedia. The original article was at Goldbach's comet. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)

Goldbach's comet is the name given to a plot of the function g(E), the so-called Goldbach function.

The Goldbach function is studied in relation to Goldbach's conjecture. The function g(E) is defined for all even integers E>2 to be the number of different ways in which E can be expressed as the sum of two primes.

Examples
 G(4) = 1, since 4 can only be expressed as the sum of one distinct pair of primes (4 = 2 + 2)
 G(22) = 3, since 22 can be expressed as the sum of 3 distinct pairs of primes (22 = 11 + 11 = 5 + 17 = 3 + 19)


Task
 Find and show (preferably, in a neat 10x10 table) the first 100 G numbers (that is: the result of the G function described above, for the first 100 even numbers >= 4)
 Find and display the value of G(1000000)


Stretch
 Calculate the values of G up to 2000 (inclusive) and display the results in a scatter 2d-chart, aka the Goldbach's Comet


See also
 Wikipedia: Goldbach's conjecture
 OEIS: A045917 - From Goldbach problem: number of decompositions of 2n into unordered sums of two primes




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