subroutine get_prime(isPrime, N) implicit none integer::i,j,N integer,parameter::prime=1,nonprime=0 integer,allocatable::isPrime(:) isPrime=prime isPrime(1)=nonprime 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 end subroutine get_prime program main implicit none interface subroutine get_prime(isPrime, N) integer::N integer,allocatable::isPrime(:) end subroutine get_prime end interface integer::M,N,i,j,sum integer,allocatable::C(:),isPrime(:) integer::memo(-1000:10000) data memo/11001*0/ read *,M, N allocate(C(N)) allocate(isPrime(2:M)) read *, C memo(M) = 1 do i=M, 1, -1 if(memo(i).eq.0) cycle do j=1, N memo(i-C(j)) = MAX(memo(i-C(j)),memo(i) + 1) end do end do call get_prime(isPrime, M) sum = M/MINVAL(C) do i=2, M if(isPrime(i).eq.0) cycle if(memo(i).eq.0) cycle sum = sum + (memo(i)-1) end do print '(i0)', sum end program main