module mdl integer*8::f(0:40,0:40) contains subroutine build() do i=0,40 do j=0,40 f(i,j)=-1 end do end do end subroutine recursive function calc(a,b,cur)result(res) integer::a,b integer*8::cur,res if(f(a,b)/=-1)then res=f(a,b) return end if if(cur==0)then f(a,b)=1 res=1 return end if res=calc(a+1,b,cur/3)+calc(a,b+1,cur/5) f(a,b)=res end function end module program main use mdl implicit none integer*8::n read*,n call build() print*,calc(0,0,n) end program