program main implicit none integer*8::N,M integer*8,allocatable::f(:) integer::i read *,N,M allocate(f(1:N)) f(1)=0 f(2)=1 do i=1,N-2 f(i+2) = MOD(f(i)+f(i+1), M) end do print '(i0)', f(N) end program main