COMP 170 (Sec. 008)    -    PROGRAM III

Due:  Monday, 5 October 1998
 
Design, test, and run a program, PrimeFactorization, which will read as input an integer, n > 2, and produce as output the prime decomposition of n.
 

Sketch of ALGORITHM Prime Factorization:
 

Let n be the number whose prime decomposition is desired.

Test n for divisibility by 2.  If yes, then via a method call, determine the highest power, p, of 2 which evenly divides n.

Replace n by n / (2p).

Test n for divisibility by 3.  If yes, then via a method call, determine the highest power, p, of 3 which evenly divides n.

Replace n by n / 3p.

Test n for divisibility by 4, etc.

Continue until n = 1.
 

Sample dialogue:

Welcome to Jean Valjean's prime factorization program.

Please enter the integer:

1996

The prime decomposition of 1996 is:

  2 raised to the power 2

  499 raised to the power 1

Do you wish to continue?  If so enter Yes;  if not enter No:

Yes

Please enter the integer:

123456789
 
 

The prime decomposition of 123456789 is:

 3 raised to the power 2

 3607 raised to the power 1

 3803 raised to the power 1

Do you wish to continue?  If so enter Yes;  if not enter No: 

No

Thank you!
 
 
 

Extra credit:

(1)  In case n is actually prime, just print:  The number that you have chosen is prime.

(2)  Using the random number generator in the java Math class, give the user a chance to select her/his own integer or a random integer.
 

What to submit:

All of the following should be contained in a two-pocket folder with your name in large letters on
the outside of the folder.

 

Mathematicians have tried in vain to this day to discover some order in the sequence of prime numbers, and we have reason to believe that it is a mystery into which the human mind will never penetrate.

 
  Course Home Page              Department Home Page            Loyola Home Page