题解:P1001 A+B Problem

· · 题解

数论好题!!

先说结论:a+b=a \texttt{and} b + a \texttt{or} b

原因:使用二进制加法。

对于 a,b 均为 1 的位,在 a \texttt{and} ba \texttt{or} b 中被算了刚好 2 次。

对于 a,b1 位是 1 的位,在 a \texttt{or} b 中被算了刚好 1 次。

Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b;
signed main(){
    cin>>a>>b;
    cout<<(a&b)+(a|b);
}