Generating the 1000th prime.
BlitzPlus Forums/BlitzPlus Beginners Area/Generating the 1000th prime.
| ||
OK I am confused as to what is involved. My goal is to develop problem solving ability. I need to generate the 1000th prime number. What math level formally would something like that be taught at? Do I want to count the 100th repetition by sorting it into a table or is my focus on actually building a prime generator. Then displaying the count? Any ideas are appreciated What are the various histories involved in understanding the structures. I am not out to get the right answers as much as to understand the nature surrounding the various semantics and structures. What are the advantages of the Eratosthenes Fermat and Mersenne Primes Are there reasons why some are favored in certain subjects? |
| ||
I would not create a mathematical, but an iterative solution if you want to get only the 1000th. Computers are very fast with that. Check all numbers from 0 to 9999 by dividing them through all already known primes. If it is not dividable add it as a new prime: ; number of primes: Dim Prime%(100) ; the first prime 'by hand': Prime(1)=1 Global Count%=1 ; now test all numbers: For Value%=2 To 99 If Test(Value)=True ; add it as a new one: Count=Count+1 Prime(Count)=Value Print Value + " is the " + Count + ". prime number" EndIf Next WaitKey End Function Test(Value%) ; compares a number with all prime numbers: For i%=2 To Count ; divide the number, then multiply it ; if the result id the same the number was dividable If Value = Value/Prime(i) * Prime(i) Return False Next Return True End Function |
| ||
Thanks I will put this in and work to understand all of it. |