No.1106 🦉 Balance Is Important in Everything
Problem Statement
There are $N$ packages in total, one each with weights $1, 2, \cdots, N$.
You will balance each of these packages on a balance scale using weights.
For the weights, there are only $2$ of each with mass $5^{k}$ ($k$ is an integer at least $0$).
That is, the masses of the weights, from lightest, are $1, 1, 5, 5, 25, 25, 125, 125, \cdots$. There is no upper limit.
Weights can be placed on either the left or the right side of the scale.
After each balancing, both the package and the weights are taken off the scale, so weights that have been used once can be used again.
Believing that balance is important in everything, you want the number of weights to also be equal on the left and right when the scale is balanced.
Count how many packages allow such a placement of weights.
Input
$N$
$N$ is an integer satisfying $1 \le N \le 10^{18}$.
Output
Among the $N$ packages, output the number of packages for which the number of weights is equal on the left and right when balanced on the scale, followed by a newline.
Sample
Sample 1
Input
4
Output
1
Therefore, among the packages with weights from $1$ to $4$, the only one for which the numbers of weights are equal is the package with weight $4$, so output $1$.
Sample 2
Input
9
Output
2
When the package weight is $8$, two weights of mass $1$ are placed on the package's side, and two weights of mass $5$ are placed on the opposite side.
Sample 3
Input
25
Output
5
When the package weight is $16$, two weights of mass $5$ are placed on the package's side, and one weight each of mass $1$ and $25$ is placed on the opposite side.
When the package weight is $20$, one weight of mass $5$ is placed on the package's side, and one weight of mass $25$ is placed on the opposite side.
When the package weight is $24$, one weight of mass $1$ is placed on the package's side, and one weight of mass $25$ is placed on the opposite side.
Sample 4
Input
3364
Output
433
Sample 5
Input
1000000000000000000
Output
55085687930311653
This is the case with the maximum input value.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
hotman78