Fourteen problems with whole numbers — several of them too big for an int.
For each one, ask how big the answer can get, not how big the input is:
- If the answer could pass 2 147 483 647, it goes in a
long long. - Make the calculation happen in
long longtoo: read the inputs intolong longfrom the start, or write1LL *at the front of a product. - A Wrong Answer on a big test and Accepted on the small ones is the classic sign of a value that outgrew its box.
- Two of them want the distance between two numbers, whichever is bigger:
abs(a - b).