program main implicit none integer::n,k,i,j integer,allocatable::num(:) character*32::cformat='(i0, (1x,i0))' read *,n,k allocate(num(n)) num(1) = 0 num(2) = 2 do i=4, n-k, 2 num(i) = i/2+1 end do do i=3, n-k, 2 num(i) = i/2 end do j = i/2 + 1 - MOD(n-k,2) do i=n-k+1,n num(i) = j end do write(cformat(5:9),'(i0)'),n-1 write(*,cformat) num end program main