__int128
仅64位 GCC , G++ 支持,且不在 C++ 标准中。如果是64位 GCC 可直接使用。
允许使用以下划线开头的库函数或宏,但具有明确禁止操作的库函数和宏除外。
所以__int128
能在比赛中进行使用。
__int128
占用128Byte的空间,数据范围是 −2127∼2127−1-2^{127} \sim 2^{127}-1−2127∼2127−1 。
精确范围是 −170141183460469231731687303715884105728∼170141183460469231731687303715884105727-170141183460469231731687303715884105728 \sim 170141183460469231731687303715884105727−170141183460469231731687303715884105728∼170141183460469231731687303715884105727 量级在1×10381\times 10^{38}1×1038 左右。
与其他类型一致 类型名 变量名
__int128 a=4,b=3;
a=10;
a+=b;
a*=b;
...
由于不在C++标准内,没有配套的输入输出工具,无法直接使用scanf
、printf
、cin
、cout
进行处理。需要自己手写输入输出。
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');
}
}
Q.E.D.