       PROGRAM GAMMAELOdr

       INTEGER ia,n,idum,j
       REAL g,gamdev

C       open(4,file='gered.dat')

       write(*,*)'Kerem ia erteket! ia:'
       read(*,*)ia
       write(*,*)'Kerem n erteket! n:'
       read(*,*)n
       do j=-1,-n,-1
	  idum=j
       g=gamdev(ia,idum)
       write(*,*)g
       enddo
C       close(4)
       stop
       end


       REAL FUNCTION gamdev(ia,idum)

       INTEGER j,idum,ia
       REAL am,e,s,v1,v2,x,y,ran1
       if(ia.lt.1)pause 'bad argument in gamdev'
       if(ia.lt.6)then
	  x=1
	  do j=1,ia
	  x=x*ran1(idum)
	  enddo
	  x=-log(x)
       else
 1           v1=ran1(idum)
	    v2=2*ran1(idum)-1
	  if(v1**2+v2**2.gt.1)goto1
	    y=v2/v1
	    am=ia-1
	    s=sqrt(2*am+1)
	    x=s*y+am
	  if(x.le.0)goto1
	    e=(1+y**2)*exp(am*log(x/am)-s*y)
	  if(ran1(idum).gt.e)goto1
       endif
       gamdev=x
       return
       END

      FUNCTION ran1(idum)

      INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
      REAL ran1,AM,EPS,RNMX
      PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,
     * NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
      INTEGER j,k,iv(NTAB),iy
      SAVE iv,iy
      DATA iv/NTAB*0/,iy/0/
      if (idum.le.0.or.iy.eq.0)then
	  idum=max(-idum,1)
	  do j=NTAB+8,1,-1
	    k=idum/IQ
	    idum=IA*(idum-k*IQ)-IR*k
	    if (idum.lt.0)idum=idum+IM
	    if (j.le.NTAB)iv(j)=idum
	    enddo
	    iy=iv(1)
      endif
      k=idum/IQ
      idum=IA*(idum-k*IQ)-IR*k
      if (idum.lt.0)idum=idum+IM
      j=1+iy/NDIV
      iy=iv(j)
      iv(j)=idum
      ran1=min(AM*iy,RNMX)
c     return

      END
