module OW_gcd

implicit none

contains

 subroutine owgcd(n,iq,q)

 integer			:: n,k,i,m,j,iq,q(:)

 k=2**n-1
 iq=0

 do i=1,k
    m=n;j=i
    do while (j .ne. m)
       if (j .gt. m) then
          j=j-m
       else
          m=m-j
       end if
    end do
    if ((j.eq.1).or.(m.eq.1)) then
       iq=iq+1
       q(iq) = i
    end if
 end do

 end subroutine

end module
