!! if k+1 = 2^n => ln(k+1) = n ln(2)
FUNCTION mersenne(k)
  IMPLICIT NONE

  INTEGER, INTENT (in) :: k
  LOGICAL :: mersenne
  INTEGER :: n

!!% A tropos
  mersenne = .TRUE.

  n = k + 1
  DO 
     IF (n == 2) EXIT

     IF (MOD(n,2) /= 0) THEN
        mersenne = .FALSE.
        EXIT
     END IF

     n = n / 2
  END DO

!!% ! B tropos
!!%
!!%  n = LOG(DBLE(k+1)) / LOG(2.0d0)
!!%
!!%  mersenne = (k+1) == 2**n



!!% ! C tropos
!!%
!!% n  = 0
!!% mersenne = .FALSE.
!!% DO 
!!%    IF (2**n >  k + 1) EXIT
!!%
!!%    IF (2**n == k + 1) THEN 
!!%       mersenne = .TRUE.
!!%       EXIT
!!%    ENDIF
!!%
!!%    n = n + 1
!!% ENDDO

END FUNCTION mersenne

PROGRAM mers
  IMPLICIT NONE

  INTERFACE 
     FUNCTION mersenne(k)
       IMPLICIT NONE

       INTEGER, INTENT (in) :: k
       LOGICAL :: mersenne
     END FUNCTION mersenne
  END INTERFACE

  INTEGER :: i

  DO i=1,10000
     IF (mersenne(i)) WRITE (*,*) i
  ENDDO

END PROGRAM mers
