recursive function solve(X, D, memo) result(res) integer*8::res, D,X,memo(1500,1500) if(memo(X,D).eq.0_8) then memo(X,D) = solve(X,D-1,memo) + solve(X-1, D, memo) end if ! print '("X:",i5,", D:",i5,", memo:",i5)',X,D,memo(X,D) res = memo(X,D) if(res.gt.10**15_8) then memo(X:1500,D:1500)=10**15_8 end if return end function solve program main implicit none type problem integer*8::D,X,T end type problem interface recursive function solve(X, D, memo) result(res) integer*8::res, D,X,memo(1500,1500) end function solve end interface integer*8::Q,i,j,k,tmp integer*8::qd,qx,qt type(problem)::P(10**4) integer*8::D,T,memo(1500,1500) !X,D data memo/2250000*0/ read *, Q read *, P(1:Q) do i=1,1500 memo(1,i) = i end do memo(:,1) = 1 do i=1,Q tmp = solve(P(i)%X, P(i)%D, memo) if(tmp.gt.P(i)%T) then print '(a)', "ZETUBOU" else print '(a)', "AC" end if end do end program main