No.1185 Perfect Multiples of 3
タグ : / 解いたユーザー数 201
作問者 :
penguinman
/ テスター :
Rho
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もしくは右上の雲マークをクリックしてアカウントを作成してください。