아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Filter

시간 제한2초메모리 제한1024 MB

요약
N이 주어질 때, 분수 x/N이 칸토어 집합에 속하는 모든 정수 x(0 ≤ x ≤ N)를 오름차순으로 출력한다.
난이도

보통10점 중 6점

유형
정수론, 수학, 재귀, 구현
정답자
아직 제출이 없습니다

문제

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:

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 (3i−1)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 0≤x≤N0 \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.

제한

  • 2≤N≤1092 \le N \le 10^9

예제1

  1. 예제 1

    입력
    12
    
    예상 출력
    0
    1
    3
    4
    8
    9
    11
    12