Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module DelPrimes
- Sub Main()
- Dim Primes As List(Of Integer) = Sieve(10000000)
- Dim table(Primes(Primes.Count - 1)) As Boolean
- Dim sum As Double = 17
- For Each prime As Integer In Primes : table(prime) = True : Next
- For i = 4 To Primes.Count - 1
- If i > Primes.Count - 1 Then Exit For
- Dim intString As String = Primes(i)
- table(0) = False
- For x = 0 To intString.Length - 1
- Dim crnt As String = intString.Remove(x, 1)
- If Not crnt.StartsWith("0") Then
- If table(crnt) = True Then
- table(0) = True
- Exit For
- End If
- End If
- Next
- If table(0) = False Then
- table(Primes(i)) = False
- Primes.RemoveAt(i)
- i -= 1
- Else
- sum += Primes(i)
- End If
- Next
- Console.WriteLine(Primes.Count & vbCrLf & sum)
- Console.ReadKey()
- End Sub
- Function Sieve(ByVal limit As Integer) As List(Of Integer)
- Dim sqrt As Integer, CrntNbr = 11
- Sieve = {2, 3, 5, 7}.ToList
- While CrntNbr < limit
- sqrt = Math.Sqrt(CrntNbr)
- For Each prime In Sieve
- If prime <= sqrt Then
- If CrntNbr Mod prime = 0 Then Exit For
- Else
- Sieve.Add(CrntNbr)
- Exit For
- End If
- Next
- CrntNbr += 2
- End While
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment