program main implicit none integer*8::win=0,total,taro_sum,jiro_sum integer::N,K,i,j integer::taro(60),jiro(60) integer,parameter::dice(6)=(/1,1,1,1,1,1/), & dice2(6)=(/0,0,0,2,2,2/) data taro/60*0/,jiro/60*0/ read *,N,K jiro(1:6) = dice(1:6) call cast_dice(jiro, dice, N-1) if(N.ne.K) then taro(1:6) = dice(1:6) call cast_dice(taro, dice, (N-1)-K) call cast_dice(taro, dice2, K) else taro(1:6) = dice2(1:6) call cast_dice(taro, dice2, N-1) end if total = 6**N taro_sum = total jiro_sum = 0 do i=1,6*N taro_sum = taro_sum - taro(i) ! gt i win = win + taro_sum*jiro(i) end do print '("0",f0.15)', DBLE(win)/(DBLE(total)*DBLE(total)) contains subroutine printer(me) integer::i integer::me(60) do i=1,6*N print *,i,me(i) end do end subroutine printer subroutine cast_dice(name,dice,M) integer,intent(out)::name(60) integer,intent(in)::M,dice(6) integer::memo(60),i,j,k data memo/60*0/ do k=1,M memo = 0 do i=k,6*(k+1) do j=1,6 memo(i+j) = memo(i+j) + name(i)*dice(j) end do end do name = memo end do end subroutine cast_dice end program main