Closing the Windows
Time limit1sMemory limit64 MB
Count how many of the N windows end up open after each person toggles the windows whose numbers are multiples of their index.
- Level
Medium4 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
A lab room has windows and people. The windows are numbered through , and every window starts closed.
Person visits every window whose number is a multiple of . At each of those windows, the person closes it if it is open and opens it if it is closed. Person acts first, then person , and so on through person . Count how many windows are open at the end.
For the process runs like this.
- Person opens windows , the multiples of . The state is (open, open, open).
- Person closes window , the multiple of . The state is (open, closed, open).
- Person closes window , the multiple of . The state is (open, closed, closed).
Exactly window is open at the end.
Input
The first line contains , the number of windows and also the number of people. ()
Output
Print how many windows are open at the end.