(48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite (/thread-16051.html) (48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite - gerry_in_polo - 12-14-2020 02:26 PM A whole number is composite or not a prime number if there exists at least one smaller number whose square is less than or equal to the former and evenly divides the former. The square criterion limits the number of factors needed to be searched. << -> N << 0 'NF' STO 2 'T' STO WHILE T 2 ^ N ABS <= REPEAT N T MOD 0 == IF THEN NF 1 + 'NF' STO T "FACTOR" ->TAG END T 1 + 'T' STO END NF 0 == IF THEN N "PRIME" ->TAG ELSE NF "NFACTORS<√N" ->TAG N "COMPOSITE" ->TAG END >> >> The program lists all the factors (if any) of the number being tested up to or less than the square root of the number, the count of such factors found and finally an indication of whether the number is prime or composite. RE: (48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite - John Keith - 12-15-2020 08:01 PM The 49g and 50g have built-in commands FACTOR and ISPRIME? which give similar results, albeit without the explanatory tags. There is also the Factor library which is faster and returns a factor list in a format which is generally more useful in programs. None of the above applies to the HP-48, where your program would be most useful.