Taha1506's blog

By Taha1506, history, 5 months ago, In English

In today's contest I used (1<<k) to denote $$$2^k$$$ but.It turned out that (1<<k) won't generate long long values so I got time limit exceeded in test three.Then I decide to implement power using multiply and return both the power and the number itself but it take more amount of code and I used to spend many time debugging it.Any suggestions?

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
5 months ago, # |
  Vote: I like it +75 Vote: I do not like it

Bruh use 1ll << k

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did it here:100370277

    But it didn't work.Am I missing something?

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Ha ha , once upon a time, I used to think what the hell is this 1LL, then faced the same problem as above some days later, realized how important it is...

»
5 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Using $$$1LL$$$ << $$$k$$$ will generate long long data type values.

»
5 months ago, # |
  Vote: I like it -30 Vote: I do not like it

Very weird that 1770 rated doesn't know this.

  • »
    »
    5 months ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    Not that weird. When I learned that my "true" rating was surely above 1770.

    In general rating and knowledge of language features are not as correlated as one might think.

»
5 months ago, # |
  Vote: I like it +31 Vote: I do not like it

As to why: from the language's perspective, there is integer promotion (for example, when we have (char a) <op> (short b), both are promoted to an int). Promoting to a long long by default would be a very costly choice, at least for 32-bit programs. And the compiler would have a very hard time guessing whether a particular operation should result in long long instead of int, and often guess wrong anyway. So it just doesn't try anything of the sort.

Interestingly, in (int a) << (long long b), the result is still an int. And the result when not ($$$0 \le b < 32$$$) is undefined behavior.