You are on the Home/Other Tutorials/Project Euler/Problem 10 page
Google
Web This Site

Project Euler - Problem 10

More about Project Euler.

Problem description

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Solution

Reusing the AllPrimes routine from Euler 7, the additional code was trivial.
Option Explicit

Sub Euler10()
    Dim Rslt() As Long, SumRslt As Variant
    SumRslt = CDec(0)
    Rslt = AllPrimes(2000000)
    Dim I As Long
    For I = LBound(Rslt) To UBound(Rslt)
        SumRslt = SumRslt + CDec(Rslt(I))
        Next I
    Debug.Print SumRslt
    End Sub