B2001 题解
题目大意:给定两个整数
前置芝士——豚鼠定理
我们可以用豚鼠定理将其简化为:对于给定的
因为
cpp代码:
#include<bits/stdc++.h>
using namespace std;
__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;
}
void write(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9) write(x/10);
putchar(x%10^48);
}
__int128 sqr1(__int128 x){
return x*x;
}
__int128 times(__int128 x,__int128 y){
__int128 z=2;
return x*y*z;
}
__int128 sqrt1(__int128 x){
unsigned __int128 l=0,r=1e19,ans=1;
while(l<=r){
unsigned __int128 mid=(l+r)/2;
if(mid*mid>x){
r=mid-1;
}else{
l=mid+1;
ans=mid;
}
}
return ans;
}
int main(){
__int128 a=read(),b=read(),t;
t=max(a,b);
write((t|0)+(__int128)( sqrt1(sqr1(a)+times(a,b)+sqr1(b))-sqrt1(sqr1(a)-times(a,b)+sqr1(b)) )/2 );
return 0;
}