Logo
(追記) (追記ここまで)

28316번 - The Filter 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB522100.000%

문제

Alice, the mathematician, likes to study real numbers that are between 0ドル$ and 1ドル$. 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 3ドル$ filters look like this:

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

  • Consider the number line from 0ドル$ to 1ドル$.
  • Split this number line into 3ドル^k$ equal-sized pieces. There are 3ドル^k + 1$ points and 3ドル^k$ intervals.
  • The $k$-th filter consists of the 2ドル^\text{nd}$ interval, 5ドル^\text{th}$ interval, 8ドル^\text{th}$ interval, and in general, the $(3i - 1)^\text{th}$ interval. The points are not part of the $k$-th filter.

Alice has instructions for constructing the Cantor set. Start with the number line from 0ドル$ to 1ドル$. 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 $N,ドル Alice would like to know which fractions $\frac{x}{N}$ are in the Cantor set.

입력

The first line contains the integer $N$.

출력

Output all integers $x$ where 0ドル \le x \le N$ and $\frac{x}{N}$ is in the Cantor set.

Output the answers in increasing order. The number of answers will not exceed 10ドル^6$.

제한

  • 2ドル \le N \le 10^9$

예제 입력 1

12

예제 출력 1

0
1
3
4
8
9
11
12

Here is a diagram of the fractions and the first 4ドル$ filters. In reality, there are infinitely many filters.

$\dfrac{5}{12},ドル $\dfrac{6}{12},ドル and $\dfrac{7}{12}$ are not in the Cantor set because they were covered by the 1ドル^\text{st}$ filter.

Furthermore, $\dfrac{2}{12}$ and $\dfrac{10}{12}$ are not in the Cantor set because they were covered by the 2ドル^\text{nd}$ filter.

It can be shown that the remaining fractions will pass through all filters.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCC 2023 Senior Division 5번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /