#T752. 开关灯问题

开关灯问题

Description

Suppose there are N lights (N is a positive integer not greater than 5000), numbered sequentially from 1 to N, all initially turned on. There are also M people (M is a positive integer not greater than N), numbered sequentially from 1 to M.

The first person (No. 1) turns off all the lights. The second person (No. 2) turns on the lights numbered in multiples of 2. The third person (No. 3) toggles the lights numbered in 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 like the third person, toggling all lights that 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 turned-off lights in order, separated by English commas (,).

10 10 、
1,4,9

译文

CodesOnline