题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/68f53b4f75fa43d55dcc60b84d9833e6.png)
输入
输入一个整数x
输出
输出函数值
样例输入1
3
样例输出1
5
样例输入2
10
样例输出2
41
做法1
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a012ffa2d4b7149c3f9e7ca085d4e809.png)
#include <bits/stdc++.h>
using namespace std;
int f(int x) {
if (x <= 0) return 0;
if (x == 1) return 1;
return 3 * f((x + 1) / 2) - 1;
}
int main() {
int x;
cin >> x;
cout << f(x) << endl;
return 0;
}