__int128的使用

dzk在做蛋糕上的草莓是蛋糕的灵魂这道题的时候写的 \(longlong\) 爆了,补题的时候经lwq指点,学习了__int128的用法

int 最大值 \(2^{32-1}-1\)

long long最大值 \(2^{64-1}-1\)

__int128最大值 \(2^{128-1}-1\)

关于__int128:只能进行四则运算,不能用cin和cout来输出,不能用位运算来定义最大值。

  • __int128的输入和快读如出一辙:
__int128 read()
{
	__int128 x=0,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();
	}
	return x*f;
}
  • __int128的输出利用stack倒一遍即可:
void out(__int128 x)
{
	if(x<0) putchar('-'),x=-x;
	stack<int> sta;
	while(x) sta.push(x%10),x/=10;
	while(!sta.empty()) putchar(sta.top()+'0'),sta.pop();
}
posted @ 2024-08-12 14:37  Du_zk  阅读(171)  评论(0)    收藏  举报