题解:CF2085C Serval and The Formula
Magallan_forever · · 题解
简要说明题意:
已知
题目分析:
众所周知
考虑到
代码如下:
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int T;
long long x,y,t,temp,cnt,k;
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&x,&y),k=0ll,t=(x&y);
if(x==y){
printf("-1\n");
continue;
}
while(t){
temp=(t&(-t)),temp=(temp<<1)-1;
cnt=min(((x&temp)^temp)+1,((y&temp)^temp)+1);//计算要加到进位差多少,可能有更简单的表达方式?
k+=cnt,x+=cnt,y+=cnt;
t=(x&y);
}
printf("%lld\n",k);
}
return 0;
}
/*
1
3 7
*/