Advertisement
Guest User

A+B problem

a guest
Jan 5th, 2015
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define llong long long
  3. using namespace std;
  4.  
  5. int a, b;
  6. int binplus(int a, int b) {
  7.     if(!b)  return a;
  8.     if(b % 2 == 0) {
  9.             int res = binplus(a, b / 2);
  10.             return res + b / 2;
  11.     }
  12.     else {
  13.         return binplus(a, b - 1) + 1;
  14.     }
  15. }
  16.  
  17. int main() {
  18.     cin >> a >> b;
  19.     if(a < 0 && b < 0) a = -a, b = -b, cout << '-';
  20.     else if(b < 0) swap(a, b);
  21.     cout << binplus(a, b);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement