CONCEPT · Legendary
Integer overflow
also long long · int64
C++ int is 32-bit. Products of two 1e9 values, prefix sums of 2e5 × 1e9, and n(n+1)/2 at n = 1e9 all need 64-bit.
Intuition
If any intermediate can exceed 2·10⁹, use 64-bit. Multiply before you divide only when you have the bits.
When to reach for it
- Every C++ solution with large values
- Counting pairs
- Geometry cross products
Usual pits
- 1LL * a * b vs a * b * 1LL (a*b still overflows first)
- JavaScript is safe until 2⁵³ — then you need BigInt
No full lesson yet — this card is a placeholder for the Contest Craft swarm.