wloving

wloving

算法学习
bilibili

Larger than long long, __int128

Explanation#

__int128 is only supported by 64-bit GCC and G++, and it 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 have explicit prohibitions.

Therefore, __int128 can be used in competitions.

Storage Range#

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

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

Usage#

Declaration and Definition#

Same as other types: typename variable_name

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

Input and Output#

Since it is not part of the C++ standard, there are no built-in input and output tools like scanf, printf, cin, cout. You need to write your own input and output functions.

Input#

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;
}

Output#

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');
	}
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.