P1876 Turning On the Lights
Background
Does this problem title look familiar? In fact, if you know the method, the code could hardly be shorter. But if you don’t? Well... figure it out yourself.
Description
At the start, all lights are off (note: off!). The person numbered $1$ comes and turns on all lights whose indices are multiples of $1$. The person numbered $2$ turns off all lights whose indices are multiples of $2$. The person numbered $3$ toggles all lights whose indices are multiples of $3$ (those that are on are turned off, those that are off are turned on), and so on, until the person numbered $N$ finishes.
Given $N$, after $N$ rounds, determine which lights are still on.
Input Format
A single number $N$, representing both the number of lights and the number of rounds.
Output Format
Several numbers, the indices of the lights that are on.
Explanation/Hint
Constraints
For $100 \%$ of the testdata, $1 \le N \le 2^{40}$.
Additional Notes
Math problem!
Translated by ChatGPT 5