#T549. 开关灯问题

开关灯问题

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 (number 1) turns off all the lights. The second person (number 2) turns on the lights numbered in multiples of 2. The third person (number 3) performs the opposite operation on 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 the same as person 3, performing the opposite operation on the lights numbered in multiples of their own number.

The question is: After the M-th person has performed their operation, which lights remain 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 English commas (,).

10 10 、
1,4,9

译文

CodesOnline