Please read the new rule regarding the restriction on the use of AI tools. ×

tgbaodeeptry's blog

By tgbaodeeptry, history, 3 years ago, In English

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

  • Vote: I like it
  • +22
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +54 Vote: I do not like it

Yes. Since a + b > n means a > n - b you can just check that.

»
3 years ago, # |
  Vote: I like it -57 Vote: I do not like it

Convert them all to double.

»
3 years ago, # |
  Vote: I like it +21 Vote: I do not like it
»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thats for multiplication I guess.