以下是加法电路器实现加法的代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int add(int x , int y){
if(!x) return y;
add((x & y) << 1 , x ^ y);
}
int a , b;
int main(){
cin >> a >> b;
cout << add(a , b) << endl;
return 0;
}
这个代码是可以过P1001的,但是他的复杂度显然不是O(1),那为什么我们学的 a$$+$$b 的写法是O(1),这个却不是,是因为什么?