转自:http://www.cnblogs.com/litstrong/archive/2011/05/19/2051516.html
计算a+b,不使用+,-,*,/,用^实现加法,用&实现进位,代码如下,复杂度log级别的,有意思哈~
1 #include <iostream> 2 #include <string> 3 #include <queue> 4 #include <complex> 5 using namespace std; 6 int go(int a, int b) 7 { 8 int sum = a ^ b; 9 int jin = a & b; 10 if(jin) 11 return go(sum, jin << 1); 12 else 13 return sum; 14 } 15 int main() 16 { 17 int a, b; 18 cin >> a >> b; 19 cout << go(a, b); 20 }