#3972.计算2的N次方 题解 审核通过

CPP 刷题王 2025-05-19 16:39:43 9

解题思路

众所周知有个东西叫作 __int128,范围是 ,反正比 大,因此我们直接算就可以了。

但是 cout 不能直接输出 __int128,因此需要自己写输出。

#include <bits/stdc++.h>
using namespace std;
inline void write(__int128 n) {
    string b = "";
    while (n) {
        int t = n % 10;
        b = to_string(t) + b;
        n /= 10;
    }
    cout << b;
}
signed main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    __int128 a = 1;
    while (n--) {
        a *= 2;
    }
    write(a);
	return 0;
}
{{ vote && vote.total.up }}