There are 1000 doors $D_1, D_2, . . . , D_{1000}$ and 1000 persons $P_1, P_2, . . . , P_{1000}$.
Initially all the doors were closed. Person $P_1$ goes and opens all the doors.
Then person $P_2$ closes door $D_2, D_4, . . . , D_{1000}$  and leaves the odd numbered doors open. Next $P_3$ changes the state of every third door, that
is, $D_3, D_6, . . . , D_{999}$ . (For instance, $P_3$ closes the open door $D_3$ and opens
the closed door D6, and so on). Similarly, $P_m$ changes the state of the
the doors $D_m, D_{2m}, D_{3m}, . . . , D_{nm}, . . .$ while leaving the other doors untouched. Finally, $P_{1000}$ opens $D_{1000}$ if it was closed or closes it if it were
open. At the end, how many doors will remain open?
1. Initially, all 1000 doors are closed.
2. Person $P_1$ opens all the doors, so all doors $D_1, D_2, \ldots, D_{1000}$ are now open.
3. Person $P_2$ closes every second door, i.e., $D_2, D_4, \ldots, D_{1000}$. Now, all odd-numbered doors remain open, and all even-numbered doors are closed.
4. Person $P_3$ changes the state of every third door, i.e., $D_3, D_6, \ldots, D_{999}$. This means if a door is open, it will be closed, and if it is closed, it will be opened.
5. This process continues with each person $P_m$ changing the state of every $m$-th door.

To determine the final state of each door, we need to consider how many times each door is toggled. A door $D_k$ is toggled by person $P_i$ if and only if $i$ divides $k$. Therefore, the number of times door $D_k$ is toggled is equal to the number of divisors of $k$, denoted as $d(k)$.

6. A door will end up open if it is toggled an odd number of times. This happens if and only if $d(k)$ is odd.
7. The number of divisors $d(k)$ is odd if and only if $k$ is a perfect square. This is because divisors generally come in pairs, except when $k$ is a perfect square (e.g., $1 \times 1$, $2 \times 2$, etc.).

8. We need to find the number of perfect squares between 1 and 1000. The perfect squares in this range are $1^2, 2^2, 3^2, \ldots, n^2$ where $n^2 \leq 1000$.
9. The largest integer $n$ such that $n^2 \leq 1000$ is $n = \left\lfloor \sqrt{1000} \right\rfloor$.

Calculating $\sqrt{1000}$:
\[
\sqrt{1000} \approx 31.62
\]
Thus, $\left\lfloor \sqrt{1000} \right\rfloor = 31$.

Therefore, there are 31 perfect squares between 1 and 1000.

The final answer is $\boxed{31}$.