問題一覧 > 通常問題

No.1185 Perfect Multiples of 3

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 201
作問者 : penguinman / テスター : Rho
お気に入りにしたユーザー ProblemId : 4875 / 自分の提出
問題文最終更新日: 2021-01-17 04:28:35
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
技術室奥プログラミングコンテスト#5 Day1 (順位表) の他の問題:

Problem Statement

Penguinman likes multiples of $3$. Having nothing to do, Penguinman defined something called a more perfect multiple of $3$ and decided to count how many there are.

According to Penguinman's definition, an integer $X$ is a "perfect multiple of $3$" if it satisfies all of the following $3$ conditions.

  • $X$ is positive.
  • $X$ is a multiple of $3$ with at least $2$ digits in base $10$ notation.
  • Let $D$ be the number of digits of $X$ in base $10$ notation. For any $i,j (0≤i<j < D)$, the sum of the digit in the $10^i$ place and the digit in the $10^j$ place is a multiple of $3$.

Since there are infinitely many such integers, Penguinman decided to count the perfect multiples of $3$ that are at most $N$, but is in despair at how many there are.

It can't be helped, so please count them on Penguinman's behalf.

Input

$N$
  • $10≤N≤10^9$
  • $N$ is an integer

Output

Print the number of perfect multiples of $3$ that are at most $N$ on $1$ line.

Sample

Sample 1
Input
15
Output
2

The only perfect multiples of $3$ that are at most $15$ are the $2$ numbers $12$ and $15$, so print $2$.

Sample 2
Input
300
Output
31

Sample 3
Input
100000
Output
1038

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。