PROGRAM Factorize
   IMPLICIT NONE

   INTEGER  :: Input
   INTEGER  :: Divisor
   INTEGER  :: Count

   READ(*,*) Input

   Count = 0

   DO
      IF ( MOD( Input, 2 ) /= 0 .OR. Input == 1 ) EXIT
      Count  = Count + 1
      WRITE(*,*) 'Factor # ', Count , ': ', 2
      Input = Input / 2
   END DO

   Divisor = 3
   DO
      IF ( Divisor > Input ) EXIT
      DO 
         IF ( MOD(Input, Divisor) /= 0 .OR. Input == 1 ) EXIT
         Count = Count + 1
         WRITE(*,*) 'Factor # ', Count,': ', Divisor
         Input = Input / Divisor
      END DO
      Divisor = Divisor + 2
   END DO 

END PROGRAM Factorize
