跳到正文

题解

题解:P1001 A+B Problem

dulinfan2023约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月10日
收录
2026年5月27日
更新
2026年11月10日
篇幅
约 1 分钟
获赞
16
题目
P1001

版本

  1. v1当前

数论好题!!

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

原因:使用二进制加法。

对于 a,ba,b 均为 11 的位,在 aa and\texttt{and} bb 和 aa or\texttt{or} bb 中被算了刚好 22 次。

对于 a,ba,b 有 11 位是 11 的位,在 aa or\texttt{or} bb 中被算了刚好 11 次。

Code:

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