subroutine get_prime(PrimeList, N) implicit none integer::i,j,N integer,parameter::prime=1,nonprime=0,unkown=-1 integer,allocatable::isPrime(:), PrimeList(:) integer,allocatable::numlist(:) allocate(isPrime(N)) isPrime=prime isPrime(1)=nonprime isPrime(2:3)=prime do i=2, FLOOR(SQRT(REAL(N))) if(isPrime(i).eq.prime) then do j=i+i, N, i isPrime(j) = nonprime end do end if end do allocate(numlist(N)) numlist=(/(i,i=1,N)/) PrimeList=pack(numlist,isPrime(numlist).eq.prime) end subroutine get_prime program main implicit none interface subroutine get_prime(PrimeList, N) integer::N integer,allocatable::PrimeList(:) end subroutine get_prime end interface integer::N,iswin,i,j integer,parameter::win=1,lose=0 integer,allocatable::W(:),PrimeList(:) read *,N allocate(PrimeList(N)) call get_prime(PrimeList, N) allocate(W(2*N)) W(0:1)=win w(2:N)=lose do i=0, N if (W(i).eq.win) cycle do j=1, SIZE(PrimeList) W(i+PrimeList(j))=win end do end do if(w(N).eq.win) then print '(a)',"Win" else print '(a)',"Lose" end if end program main