Jump to content

Cuban primes: Difference between revisions

m
changed some spellings of "cuban" (should be lower case) in some comments (but not any programs)..
m (added a note about not capitalizing "cuban".)
m (changed some spellings of "cuban" (should be lower case) in some comments (but not any programs)..)
Line 665:
=={{header|Visual Basic .NET}}==
===Corner Cutting Version===
This language doesn't have a built-in for a ''IsPrime()'' function, so I was surprised to find that this runs so quickly. It builds a list of primes while it is creating the table. Since the last item on the table is larger than the square root of the 100,000th Cubancuban prime, there is no need to continue adding to the prime list while checking up to the 100,000th Cubancuban prime. I found a bit of a shortcut, if you skip the iterator by just the right amount, only one value is tested for the final result. It's hard-coded in the program, so if another final Cubancuban prime were to be selected for output, the program would need a re-write. If not skipping ahead to the answer, it takes a few seconds over a minute to eventually get to it (see Snail Version below).
<lang vbnet>Module Module1
Dim primes As New List(Of Long)
Line 729:
Computation time was 0.2968064 seconds</pre>
===Snail Version===
This one doesn't take any shortcuts. It could be sped up (Execution time about 15 seconds) by threading chunks of the search for the 100,000th Cubancuban prime, but you would have to take a guess about how far to go, which would be hard-coded, so one might as well use the short-cut version if you are willing to overlook that difficulty.
<lang vbnet>Module Program
Dim primes As New List(Of Long)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.