program main implicit none integer :: N integer :: i, j, num, tmp !integer, allocatable :: A(:) integer :: A(10000) read *, N !allocate(A(N)) do i = 1, N A(i) = -1 end do A(1) = 1 do i = 1, N do j = 1, N if (A(j) /= i) then cycle end if num = 0 tmp = j do while (tmp > 0) num = num + mod(tmp, 2) tmp = tmp / 2 end do if (j - num > 0 .and. A(j - num) == -1) then A(j - num) = i + 1 end if if (j + num <= N .and. A(j + num) == -1) then A(j + num) = i + 1 end if end do ! print *, A(:) end do print *, A(N) end program main