The Filter | 프로그래밍의 벗 PivotOJ
PivotOJ

The Filter

시간 제한: 2000ms메모리 제한: 1024MB출처: CCC 2023 SeniorBOJ 28316
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Alice, the mathematician, likes to study real numbers that are between 00 and 11. Her favourite tool is the filter.

A filter covers part of the number line. When a number reaches a filter, two events can happen. If a number is not covered by the filter, the number will pass through. If a number is covered, the number will be removed.

Alice has infinitely many filters. Her first 33 filters look like this:

[이미지 1]

In general, the kk-th filter can be defined as follows:

  • Consider the number line from 00 to 11.
  • Split this number line into 3k3^k equal-sized pieces. There are 3k+13^k + 1 points and 3k3^k intervals.
  • The kk-th filter consists of the 2nd2^\text{nd} interval, 5th5^\text{th} interval, 8th8^\text{th} interval, and in general, the (3i1)th(3i - 1)^\text{th} interval. The points are not part of the kk-th filter.

Alice has instructions for constructing the Cantor set. Start with the number line from 00 to 11. Apply all filters on the number line, and remove the numbers that are covered. The remaining numbers form the Cantor set.

Alice wants to research the Cantor set, and she came to you for help. Given an integer NN, Alice would like to know which fractions xN\frac{x}{N} are in the Cantor set.

입력

The first line contains the integer NN.

출력

Output all integers xx where 0xN0 \le x \le N and xN\frac{x}{N} is in the Cantor set.

Output the answers in increasing order. The number of answers will not exceed 10610^6.

예제

예제 1

입력
12
출력
0
1
3
4
8
9
11
12
코드를 제출하려면 로그인하세요.