luogu#P2235. [HNOI2002] Kathy函数

    ID: 1230 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP高精度2002各省省选湖南数位 DP

[HNOI2002] Kathy函数

Problem Description

Tiger likes math very much, so he joined the school's extracurricular math club. In the club, the teacher introduced the Kathy function to Tiger, which is defined as:

$$\left\{ \begin{aligned} &f(1)=1\\ &f(3)=3\\ &f(2n)=f(n)\\ &f(4n+1)=2f(2n+1)-f(n)\\ &f(4n+3)=3f(2n+1)-2f(n) \end{aligned} \right.$$

Tiger became very interested in the Kathy function, and through studying he found that many numbers nn satisfy f(n)=nf(n)=n.

Given a number mm, he wants you to find the number of positive integers nn such that f(n)=nf(n)=n, where nmn \leq m.

Input Format

The input contains a single line with an integer mm.

Output Format

Output a single integer: the number of positive integers nn with nmn \leq m that satisfy f(n)=nf(n)=n.

5
3

Hint

Constraints

For all testdata, it is guaranteed that 1m101001 \leq m \leq 10^{100}.

Translated by ChatGPT 5