(11C) Prime or Not Prime Number - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (11C) Prime or Not Prime Number (/thread-9976.html) |
(11C) Prime or Not Prime Number - Gamo - 01-20-2018 01:04 PM This program check to see if the number is Prime or not Prime number. Result 0 is Not Prime Number Result 1 is Prime Numer Code:
Here is another program to develop the Next Number of Prime. Code:
Example: if the start number is prime the same starting number repeated. Start 110 B > 113 > Repeat R/S > 127, 131, 137, 139,.... Start 13 B > 13 > Repeat R/S > 17, 19, 23, 29,..... Large number will compute faster with the modern 15C Try this number 899,880,277 to start. Repeat R/S for next prime is 899,880,281 in 2 second using HP-15C Emulator on PC. Gamo RE: (11C) Prime or Not Prime Number - Dieter - 01-20-2018 06:17 PM (01-20-2018 01:04 PM)Gamo Wrote: This program check to see if the number is Prime or not Prime number. Your program divides the input n by every divisor from int(sqrt(n)) down to 2. Why don't you simply use DSE then? Code: LBL A But this method is not very efficient as it also checks all even divisors. These could be sorted out. Also testing the divisors in ascending order usually is much faster. For numbers up to 1 000 000 you can use ISG which is faster than a manually controlled loop: Code: LBL A For n > 1 000 000 a manually controlled loop is required: Code: LBL A This version returns the smallest divisor of n. If this is 1, n is prime. ;-) Example: 13573 f [A] => 7 n is divisible by 7 13577 f [A] => 1 n is prime Dieter |