#P10571. [JRKSJ R8] 三七二十一

    ID: 10911 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2024洛谷原创O2优化洛谷月赛Ad-hoc

[JRKSJ R8] 三七二十一

Problem Description

You are given a digit string ss consisting of digits from 191\sim 9. Define the number represented by a digit string ss as the decimal value obtained by treating it as a base-10 number. Formally, for a digit string ss of length nn, the represented number is i=1n10nisi\sum_{i=1}^n 10^{n-i}s_i.

You may perform several operations on this digit string. In each operation, you can choose a position 1pn1\le p\le n and change sps_p to any digit from 191\sim 9. You need to make sure that this digit string has no non-empty substring whose represented number is 2k(kN)2^k(k\in \N), i.e., any non-negative integer power of 22. Please find the minimum number of operations.

Input Format

One line containing a digit string ss.

Output Format

One line containing an integer representing the answer.

2468
3
164
2
65535
0

Hint

Sample Explanation

For sample 11, the non-empty substrings of ss whose represented numbers are non-negative integer powers of 22 are 2,4,82,4,8. Changing ss to 59635963 is one of the optimal solutions.

For sample 22, the non-empty substrings of ss whose represented numbers are non-negative integer powers of 22 are 1,4,16,641,4,16,64. Changing ss to 666666 is one of the optimal solutions.

Constraints

This problem uses bundled testdata.

Let n=sn=|s|.

Subtask\text{Subtask} nn\le Score
11 44 1010
22 88
33 1717 2020
44 10310^3
55 10610^6 4040

For 100%100\% of the testdata, 1n1061\le n\le 10^6, and ss consists of digits from 191\sim 9.

Translated by ChatGPT 5