验证"哥德巴赫猜想".1742年6月,德国数学家哥德巴赫在给彼得堡的大数学家欧拉的信中提出一个问题:任何大于6的偶数均可以表示为两个素数之和吗?欧拉复信道:"任何大于6的偶数均可以表示为两个素数之和,这一猜想我还不能证明,但我确信无疑地认为这是完全正确的定理.

解决方案 »

  1.   

    Public Function Twinprime(ByVal N As Long) As String 
    Dim E, i, P, Q, R, S, T As Long 
    Dim K As String K = "         3" & "         5" & vbNewLine 
    E = 1 
    Q = N \ 3 + 1 
    For i = 1 To Q Step 2 
        R = i \ 16: S = base(i And 15): T = Primes(R) And S 
        If T = 0 Then 
            P = 3 * i + 1 + (i And 1) 
            If P + 2 < N Then 
                R = (i + 1) \ 16: S = base((i + 1) And 15): T = Primes(R) And S 
                If T = 0 Then 
                    If LenB(K) < 65500 Then 
                        K = K & Space(10 - Len(P)) & P & Space(10 - Len(P + 2)) & P + 2 & vbNewLine 
                    End If 
                    E = E + 1 
                End If 
            Else 
                Exit For 
            End If 
        End If 
    Next i 
    Twinprime = K & "Total:" & E 
    End Function