wloving

wloving

算法学习
bilibili

比long long 更大的__int128

说明#

__int128 仅 64 位 GCC,G++ 支持,且不在 C++ 标准中。如果是 64 位 GCC 可直接使用。

关于 NOI 系列活动中编程语言使用限制的补充说明中表明:

允许使用以下划线开头的库函数或宏,但具有明确禁止操作的库函数和宏除外。

所以__int128能在比赛中进行使用。

存储范围#

__int128占用 128Byte 的空间,数据范围是
212721271-2^{127}\sim 2^{127}-1

精确范围是 170141183460469231731687303715884105728170141183460469231731687303715884105727-170141183460469231731687303715884105728 \sim 170141183460469231731687303715884105727 量级在1×10381\times 10^{38} 左右。

使用方式#

声明定义#

与其他类型一致 类型名 变量名

__int128 a=4,b=3;
a=10;
a+=b;
a*=b;
...

输入输出#

由于不在 C++ 标准内,没有配套的输入输出工具,无法直接使用scanfprintfcincout 进行处理。需要自己手写输入输出。

输入#

void read(__int128 &ans){
    __int128 x,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();
    }
    ans=x*f;
}

输出#

void output(__int128 x){
	if(x<0){
		putchar('-');
		x*=-1;
	}
	int ans[35]={0},top=0;
	do{
		ans[top++]=x%10;
		x/=10;
	}while(x);
	while(top){
		putchar(ans[--top]+'0');
	}
}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。