1.7 KiB
1.7 KiB
关于$__int128$的使用
正常来说,unsigned long long已经是可以定义的最大的类型了,但是如果数据范围超过了$2^64$就会爆炸。如果要处理比其大一点又不是那么大的数,就可以使用__int128这个定义。
$NOI$及$CSP$系列中可以正常使用__int128:
https://www.cnblogs.com/littlehb/p/15935662.html
\_\_int128 就是占用$128$字节的整数存储类型。由于是二进制,范围就是 $(-2^{127}) \sim (2^{127}-1)$,
如果使用了 unsigned __int128,则范围变成 $(0) ~ (2^{128})$,即约$39$位数!
由于 __int128 仅仅是 (GCC) 编译器内的东西,不在 (C++ 98/03/11/14/17/20) 标准内,且仅 (GCC4.6) 以上$64$位版本支持,很多配套都没有,只有四则运算功能, 所以要自己写输入输出。使用方法与 int long $long$无异
注意:如何确定考试中能不能用$int128$呢?办法就是先创建一个空白的$cpp$文件,然后使用 __int128 a;,测试一下,编译器不报错就是可以。
#include <bits/stdc++.h>
using namespace std;
typedef unsigned __int128 LLL;
LLL read() {
LLL x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void out(LLL x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
int main() {
LLL a, b;
a = read(), b = read();
out(a + b);
return 0;
}