問題一覧 > 通常問題

No.1106 🦉 Balance Is Important in Everything

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 52
作問者 : yuppe19 😺 / テスター : hotman78
お気に入りにしたユーザー ProblemId : 2573 / 自分の提出
問題文最終更新日: 2020-06-06 09:40:41
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
yukicoder contest 255 (順位表) の他の問題:

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
The situation is summarized in the following table.

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
The numbers of weights on the left and right are equal when the package weight is $4$ or $8$.
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
The numbers of weights on the left and right are equal when the package weight is $4, 8, 16, 20, 24$.
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もしくは右上の雲マークをクリックしてアカウントを作成してください。