正经题解 | 2的N次方
2024-05-06 16:15:57
发布于:浙江
132阅读
0回复
0点赞
题目分析
求 ,其中 最大为 超出 int,需使用 long long。
如果使用 pow 函数在输出时需要转 long long,否则数字过大时会使用科学计数法输出。
AC代码
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int main() {
int n;
cin >> n;
cout << ll(pow(2,n)) << endl;
return 0;
}
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int main() {
ll ans = 1;
int n;
cin >> n;
for(int i=0;i<n;i++)ans *= 2;
cout << ans << endl;
return 0;
}
复杂度
这里空空如也



有帮助,赞一个