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
.
The exact range is , with a magnitude of around .
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');
}
}