#include<iostream>
#include<cmath>
typedef unsigned long long ll;
using namespace std;
int main()
{
ll cnt=0;
for(int i=1;i<=;i++)
{
cnt+=pow(2,i-1);
}
cout<<cnt<<endl;
return 0;
}
跑出来结果为0,很明显for循环里变量爆了,换了无符号整数还是不行,于是另想思路。经过简单的数学演算后发现,题目中所求为1+2+4+8+…很明显为等比数列前项之和,于是写下如下代码:
#include<iostream>
#include<cmath>
typedef unsigned long long ll;
using namespace std;
int main()
{
ll a=pow(2,)-1;
cout << a << endl;
return 0;
}