方法一:
T(n) = 2 ^ n - 1
#include <iostream>
using namespace std;
int main() {
int n;
long long step = 1;
cin >> n;
int k = 1;
while (k <= n) {
step *= 2;
k ++;
}
cout << step - 1 << endl;
return 0;
}
方法二:
#include <iostream>
using namespace std;
int main() {
int n;
long long step = 1;
cin >> n;
if (n == 0) {
cout << "0" << endl;
return 0;
}
int k = 2;
while (k <= n) {
step = step * 2 + 1;
k ++;
}
cout << step << endl;
return 0;
}