Assume I have 3 long long varables a, b and n. And them are approximately (max long long)( 2.10^18 ).
So, are there any ways that I can check if a + b is larger than n?
Thanks so much guys
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3582 |
| 5 | strapple | 3515 |
| 6 | tourist | 3473 |
| 7 | Radewoosh | 3418 |
| 8 | Um_nik | 3376 |
| 9 | potato167 | 3368 |
| 10 | maroonrk | 3361 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
Assume I have 3 long long varables a, b and n. And them are approximately (max long long)( 2.10^18 ).
So, are there any ways that I can check if a + b is larger than n?
Thanks so much guys
| Name |
|---|



Yes. Since
a + b > nmeansa > n - byou can just check that.Convert them all to double.
__builtin_add_overflowhttps://wandbox.org/permlink/b6sxtBCF7900G74N
does any same function for checking multiplication result exists?
https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
Does anyone know where I can find more about this?
ive seen people use logs like log(a) + log(b) >= 18 or something along those lines. personally I just ll overflow each time so I don't use it
Thats for multiplication I guess.