wloving

wloving

算法学习
bilibili

比long long更大的__int128

说明#

__int128 is only supported by 64-bit GCC and G++ and is not part of the C++ standard. It can be directly used if you are using 64-bit GCC.

In the Supplementary Explanation on the Use Restrictions of Programming Languages in the NOI Series Activities, it is stated:

Library functions or macros starting with an underscore are allowed, except for library functions and macros that are explicitly prohibited.

Therefore, __int128 can be used in competitions.

存储范围#

__int128 occupies 128 bytes of space, and the data range is
212721271-2^{127}\sim 2^{127}-1.

The precise range is 170141183460469231731687303715884105728170141183460469231731687303715884105727-170141183460469231731687303715884105728 \sim 170141183460469231731687303715884105727, with a magnitude of around 1×10381\times 10^{38}.

使用方式#

声明定义#

Same as other types: type name

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

输入输出#

Since it is not part of the C++ standard, there are no corresponding input and output tools available, and you cannot directly use scanf, printf, cin, cout for processing. You need to write your own input and output functions.

输入#

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');
	}
}
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。