(12C+) how many primes between two numbers
|
06-30-2019, 11:30 PM
(This post was last modified: 06-30-2019 11:41 PM by Don Shepherd.)
Post: #1
|
|||
|
|||
(12C+) how many primes between two numbers
Here is a cute little program for the 12c+ that will tell you the number of prime numbers between two numbers you specify. It takes a rather brute force approach, which is why I recommend it for the 12c+ and not the slower 12c.
It also uses the N financial register as a flag. If you set N=0, it will just tell you the number of primes between the two numbers you specify. If you set N to anything else, it will pause and show you (briefly) each prime that it finds, and give you the total primes at the end. I think this is a neat and easy way to use N as a flag. To use the program, set N to 0 or non-zero depending upon whether you want to see each prime, then enter your range in X and Y (lower point in Y, upper point in X), then press R/S and be amazed. It works best if your range is under 1000 or 2000, because although the 12c+ is fast, it is still brute force. Code:
|
|||
08-22-2019, 06:48 AM
(This post was last modified: 08-22-2019 07:40 AM by Gamo.)
Post: #2
|
|||
|
|||
RE: (12C+) how many primes between two numbers
Very nice program tested and work great !!
I just happen to see the example program to "Generate Prime Number" from the HP-35S User Manual and I use that algorithm to work on the HP-12C+ or Emulators. I make some modification, instead of testing against square root I use X^2 this will run faster for large number. Procedure: If the input number is already prime the same number is display if not the next prime larger than the previous number display. FIX 0 n [R/S] display Prime Number [R/S] next Prime Number Program: Code:
Remark: Is there a better algorithm than this to search faster? Gamo |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)