在很多题目里面要求高精度,但是这种高精度又不是那种非常大的,可能比unsigned longlong大,所以这个时候去写高精度模板非常不划算,用__int128代替就非常不错;
但是__int128对cin,cout,print,scanf都不支持,要另写输入输出;
inline __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;
}
inline void print(__int128 x){//输出模板
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x/10);
putchar(x%10+'0');
}
#include <iostream>
using namespace std;
void myitoa(__int128_t v, char* s)
{
char temp;
int i=0, j;
while(v >0) {
s[i++] = v % 10 + '0';
v /= 10;
}
s[i] = '\0';
j=0;
i--;
while(j < i) {
temp = s[j];
s[j] = s[i];
s[i] = temp;
j++;
i--;
}
}
int main()
{
__uint128_t n = 0;
n = ~n;
int count = 0;
while(n > 0) {
count++;
n >>= 1;
}
cout << "count=" << count << endl;
cout << "__uint128_t size=" << sizeof(__uint128_t) << endl;
cout << endl;
cout << "__int128_t size=" << sizeof(__int128_t) << endl;
__int128_t x = 1100000000000000L;
__int128_t y = 2200000000000000L;
char s[40];
x *= y;
myitoa(x, s);
cout << "x=" << s << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
inline __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;
}
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);
return 0;
}