      program choixdim
      implicit none
      integer im, jm, ngrid, div,i

      print*,'im=?'
      read(*,*) im
      print*,'jm=?'
      read(*,*) jm
      ngrid=im*(jm-1)+2
      print*,'ngrid=',ngrid
      do i=1,int(sqrt(float(ngrid)))+1
         if (mod(ngrid,i).eq.0) then
             print*,ngrid/i,i,(ngrid/i)*i
         endif
      enddo
      end
