Блог пользователя Mike_Mirzayanov_Is_Pussy

Автор Mike_Mirzayanov_Is_Pussy, 4 года назад, По-английски

We know that using 1LL is necessary if we are shifting more than 32 bits but i have seen a lot of coders doing :

variable1 = (varialbe2+1LL)%mod

where variable1 and variable2 are in long long already.

Since we know that whenever we operate int and long long overall operations take place in long long . Then why most people do it ?

I mostly do it during contest to avoid penalty but afaik i never saw my program giving WA/TLE/RE if i do :

variable1 = (varialbe2+1)%mod

Has any one ever experienced that it's necessary to typecast operand which is in int to long long even if other operand is in long long already ?

  • Проголосовать: нравится
  • -13
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

It is not necessary. I think it is either a force of habit or trying to be safe, in case you think that you coded variable1 as LL even though it was actually int. It is the same reason as why you would place asserts in long codes. If we were perfect coders, there would be no need for it. But we aren't :D

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Good question

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

It's easier to always use 1LL (or 1L in Java/Kotlin) than to think about when it's fine to use 1 (in which case you can also make a mistake). It also makes the code clearer (it makes it clear that you're working with longs). For a similar reason, when using an int variable in long calculations I always cast to long even when my IDE tells me that it's unnecessary.