var
  n, f, p : integer; { n is the number to be factored, f is a prime factor }

procedure find_factor_f_in_n;
  begin
    f := 2; { the first prime factor to try, no need to try 1! }
    while ((n mod f) <> 0) and (n > f) do 
        { n mod f <> 0 means n is not divisible by f }
        { we want to exit when n <= f because when n = f, f is a factor! }
      f := f + 1; { try the next possible factor }
    if n < f then { to take care of the case when n = 1 }
      f := n
  end;

{*****************************************************}
{* MAIN PROGRAM                                      *}
{*****************************************************}

{ p is a new variable to track the power of a factor f
  - where to initialize p
  - what to initialize p to
  - how to update p
  - how to utilize p }
begin
  readln(n); { to read the number to factor }
  write(n,' = ');
  repeat
    find_factor_f_in_n;
    p := 0; { initialize p to zero, the loop tracks the value }
    repeat
      n := n div f;
      p := p + 1
    until 
      { n is no longer divisible by f } ((n mod f) <> 0)
        or
      { n is 1 } (n = 1);
    write(f);
    { only print the power when it is > 1 }
    if (p > 1) then
      write('^',p);
    if n > 1 then { n > 1 implies there will another iteration, and
                    there will be another factor printed, so we need
                    * as a separateor }
      write('*')
  until n = 1;
  writeln
end.

