官方题解
2025-07-14 08:13:56
发布于:浙江
51阅读
0回复
0点赞
T1 小午的222
题目大意
有一个形如 的数字,求这个数字可以分解出多少个 。
解题思路
本题输入的数字非常大,无法用 int
或 long long
存储,可以用 string
存储。
形如 的数字,可以看成 ,而 ,所以每个 可以分解出一个 。那么这串数字有多少个 就能分解出多少个 ,剩下 单独分解一下,即可得到答案。
参考代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main(){
string s;cin>>s;
int res=(int)s.size()-1;
int x=s[0]-'0';
while(x && x%2==0){
x/=2;
res++;
}
cout<<res<<endl;
}
这里空空如也
有帮助,赞一个