求强人帮我用fortran写一个程序

来源:百度知道 编辑:UC知道 时间:2024/07/04 03:12:42
学校有n个柜子,最开始所有的柜子都是所这的,然后有n个学生来开柜子,一个接一个。
第一个学生打开所有的柜子。第二个学生关闭从第2个柜子开始后每隔2个的柜子。第三个学生改变柜子的状态从第三个柜子开始每隔3个柜子。【改变状态=柜子是关的就打开,是打开的就关闭】....etc.
第n个学生改变柜子的状态从第n个开始每隔n个柜子。

用fortran写出来这个程序...

===========原题================
Picture a school hallway with n lockers. Initially all of the lockers are closed. Then n
students enter the hallway, one after the other. The first student opens all the lockers.
Student number 2 closes every other locker starting with the second. Student 3 changes
the state of every third locker beginning with the third. That is, if the locker is open the
student shuts it and if it is closed the student opens it. In general student number i
changes the state of every ith locker beginning with the ith.

!T代表开,F代表锁
program main
integer::i,j,k,n
logical,allocatable::a(:)
print*,"输入箱子个数"
read*,n
allocate(a(n))
a=.false.
do i=1,n
a(i:n:i)=.not.a(i:n:i)
end do
print*,a
end