题解:P1001 A+B Problem
yr409892525 · · 题解
题解:P1001 A+B Problem
首先我们需要知道三个性质。
性质
对于
发现以上四种情况都成立。
很显然,性质
有了这三条性质,我们就可以对
代码实现:
#include<bits/stdc++.h>
using namespace std;
int add(int a,int b){
if(a==0) return b;
if(b==0) return a;
return add(a^b,2*(a&b));
}
int main(){
int a,b;
cin>>a>>b;
cout<<add(a,b);
return 0;
}