module mdl integer*8::f(10000000) contains recursive function fib(n,m)result(res) integer*8::n,m,res if(f(n)/=-1)then res=f(n) else res=mod(fib(n-1,m)+fib(n-2,m),m) end if end function end module program main use mdl implicit none integer*8::i,j,k,n,m f(1)=0 f(2)=1 do i=3,size(f) f(i)=-1 end do read(*,*)n,m print*,fib(n,m) end program