#Z15108. 开关灯
开关灯
Description
Suppose there are N lights (where N is a positive integer not exceeding 5000), numbered sequentially from 1 to N, all initially turned on. There are M people (where M is a positive integer not exceeding N) also numbered sequentially from 1 to M.
The first person (No. 1) turns off all the lights. The second person (No. 2) turns on all the lights with numbers that are multiples of 2. The third person (No. 3) toggles the state of all the lights with numbers that are multiples of 3 (i.e., turns off the lights that are on and turns on the lights that are off). Following the order of increasing numbers, each subsequent person behaves the same as the third person, toggling the state of all lights whose numbers are multiples of their own number.
The question is: After the M-th person has performed their operation, which lights are turned off? Output their numbers in ascending order, separated by commas.
Input Format
Input the positive integers N and M, separated by a single space.
Output Format
Output the numbers of the lights that are turned off in order, separated by commas.
10 10
1,4,9