前言
有时候写题需要高精度,但是写起来特别麻烦;
可以试试尝试用128位的int;
编译器的gcc是不支持__int128这种数据类型的,但是提交到大部分OJ上是可以编译且能用的。
C/C++标准,IO是不认识__int128这种数据类型的,因此要自己实现IO,其他的运算,与int没有什么不同。
int&long long&int128范围
int存 1 0 9 10^9 109的数量级,long long存 1 0 18 10^{18} 1018
而int128存 1 0 38 10^{38} 1038
例子
#include <iostream>
using namespace std;
typedef __int128_t int128;
int128 read(){
int128 x=0;bool f=0;char c=getchar();
while (c<'0'||c>'9'){if (c=='-')f=1;c=getchar();}
while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f?-x:x;
}
inline void write(int128 x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int main(){
int128 a = read();
int128 b = read();
write(a+b);
}