whyhellothere
New Member
- Joined
- Sep 16, 2011
- Messages
- 1
I'm trying the google, "find the first 10 digit prime in the digits of PI problem" and I'm stuck. I have the logic for it but i keep running into mod errors.
Some of this code is lifted as I crashed while doing my last itteration and am too fried to rewrite. Any help is appreciated.
Sub prime()
Dim N As Double
Dim t As Double
Dim i As Double
Dim m As String
Dim q As Double
i = 0
m = Range("A1")
q = 10
For q = 10 To 100
t = Mid(m, 2, q)
Range("A2") = t
Dim bPrime As Boolean
For N = 2 To t ' Lower and Upper are entered by user
bPrime = True ' continue testing as long as true
Dim F As Integer
For F = 2 To t - 1 ' test all factors from 2 to N-1
If t Mod F = 0 Then
bPrime = False ' divisible, therefore composite
Exit For ' no more testing required
End If
Next
If bPrime = True Then ' If never got a factor, Prime found
Cells(5, 1).Value = t
End If
Next
Next
End Sub
Some of this code is lifted as I crashed while doing my last itteration and am too fried to rewrite. Any help is appreciated.
Sub prime()
Dim N As Double
Dim t As Double
Dim i As Double
Dim m As String
Dim q As Double
i = 0
m = Range("A1")
q = 10
For q = 10 To 100
t = Mid(m, 2, q)
Range("A2") = t
Dim bPrime As Boolean
For N = 2 To t ' Lower and Upper are entered by user
bPrime = True ' continue testing as long as true
Dim F As Integer
For F = 2 To t - 1 ' test all factors from 2 to N-1
If t Mod F = 0 Then
bPrime = False ' divisible, therefore composite
Exit For ' no more testing required
End If
Next
If bPrime = True Then ' If never got a factor, Prime found
Cells(5, 1).Value = t
End If
Next
Next
End Sub