function get_combination(N,R) result(res) integer*8::i,j,res integer*8,intent(in)::N,R res = 1 j = N do i=1, R res = (res*j)/i j = j - 1 end do return end function get_combination program main implicit none interface function get_combination(N,R) result(res) integer*8::res integer*8,intent(in)::N,R end function get_combination end interface integer*8::N,M,remain read *,N read *,M N=N/1000 remain = N-(N/M)*M print '(i0)', get_combination(M,remain)/10**9 end program main