(48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite

12142020, 02:26 PM
Post: #1




(48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite
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. 

« Next Oldest  Next Newest »

Messages In This Thread 
(48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite  gerry_in_polo  12142020 02:26 PM
RE: (48) (49g) (50g) Program To Determine If A Number Is Prime Or Composite  John Keith  12152020, 08:01 PM

User(s) browsing this thread: 1 Guest(s)