You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

关于\_\_int128的使用

正常来说,unsigned long long已经是可以定义的最大的类型了,但是如果数据范围超过了2^64就会爆炸。如果要处理比其大一点又不是那么大的数,就可以使用__int128这个定义。

NOICSP系列中可以正常使用__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;
}