module mdl integer*8::f(0:100,0:100) contains subroutine build() do i=0,100 do j=0,100 f(i,j)=-1 end do end do end subroutine recursive function calc(a,b,cur)result(res) integer*8::a,b,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::i,j,k,l,x,y,n read*,n call build() print*,calc(0_8,0_8,n) end program